Skip to content

Commit

Permalink
chore: expanded database, processed TODOs and handled exceptiosn
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed May 25, 2024
1 parent ba383c2 commit 5377320
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
33 changes: 14 additions & 19 deletions app/controllers/api/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

class Api::CalendarsController < ActionController::Base
# supply the personalised iCal feed from the user
# TODO supporting WebDAV might be nat, but not needed
def show
# TODO reservist marker
# TODO only display future activities option
# TODO multilingual/optional description
@member = Member.find_by(calendar_id: params[:calendar_id])
# member variable will be accessible in other methods as well now

# respond_to do |format|
# format.ics {
# render plain: create_calendar,
# content_type: 'text/calendar'
# }
# end
if not @member # No member with the specified hash was found
render json: { error: "Unkown hash" }, status: :not_found
return
end

respond_to do |format|
format.ics {
send_data create_personal_calendar,
Expand All @@ -22,23 +19,21 @@ def show
filename: "#{@member.first_name}_activities.ics"
}
end


# send_file calendar_path, type: 'text/calendar', disposition: 'attachment'
# else
# render json: { error: "Unkown hash" }, status: :not_found
# end TODO 500 error if @member is empty
end

def index
@member = Member.find(current_user.credentials_id) # TODO gives 500 error when not logged in
if current_user.nil?
render json: { error: "Not logged in" }, status: :forbidden
return
end # TODO heb je overal dit soort error handling?

@member = Member.find(current_user.credentials_id)
render plain: "https://koala.svsticky.nl/api/calendar/pull/#{@member.calendar_id}" # TODO can this less hard-coded?
end

# Not exposed to API directly, but through #show
def create_personal_calendar
@member = Member.find_by(calendar_id: params[:calendar_id])
@locale = I18n.locale # TODO werkt dit?
@locale = I18n.locale

# Convert activities to events, and mark activities where the member is
# is enrolled as reservist
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/src/members/activities/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function copyPersonalICSToClipboard() {
}).catch((error) => {
console.log(error)
});
}
} // TODO makes an API call even if the button is not pressed

export function get_activity_container() {
return $("#activity-container");
Expand Down
6 changes: 3 additions & 3 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def activity_url
return "https://koala.svsticky.nl/activities/#{ id }"
end

def descrption_localised(locale)
def description_localised(locale)
return locale == :nl ? description_nl : description_en
end

Expand All @@ -371,7 +371,7 @@ def google_event(loc = nil)
fmt_dt = ->(dt) { dt.utc.strftime('%Y%m%dT%H%M%SZ') }

loc = I18n.locale if loc.nil?
description = "#{ activity_url }\n\n#{ descrption_localised(loc) }"
description = "#{ activity_url }\n\n#{ description_localised(loc) }"
uri_name = URI.encode_www_form_component(name)
uri_description = URI.encode_www_form_component(description)
uri_location = URI.encode_www_form_component(location)
Expand All @@ -398,7 +398,7 @@ def whatsapp_message(loc)
location: location,
price: pc,
url: activity_url,
description: descrption_localised(loc),
description: description_localised(loc),
locale: loc)
end

Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ en:
description_nl: Dutch description
end_date: Enddate
end_time: Endtime
google_event: Add to calendar
google_event: Copy once to calendar
is_alcoholic: Alcoholic(18+)
is_enrollable: Enrollable
is_freshmans: First year students
Expand Down
2 changes: 1 addition & 1 deletion config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ nl:
description_nl: Nederlandse beschrijving
end_date: Einddatum
end_time: Eindtijd
google_event: Voeg toe aan je agenda
google_event: Kopiëer eenmalig naar kalender
is_alcoholic: Alcohol (18+)
is_enrollable: Inschrijfbaar
is_freshmans: Eerstejaars
Expand Down
3 changes: 1 addition & 2 deletions db/migrate/20240521180025_add_calendar_id_to_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ def up
record.update_columns(calendar_id: SecureRandom.uuid)
end

# Add a unique index to the UUID column, because why not
# Add an index to the UUID column, because why not
add_index :members, :calendar_id, unique: true
end

def down
# Remove the UUID column
remove_column :members, :calendar_id
end
end
5 changes: 1 addition & 4 deletions lib/icalendar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def IcalendarHelper.activityToEvent(activity, locale)
event.dtstart = activity.start_date
event.dtend = activity.end_date
event.summary = activity.name
event.description = activity.descrption_localised(locale)
event.description = activity.description_localised(locale)
event.location = activity.location
return event
end
Expand Down Expand Up @@ -38,8 +38,5 @@ def IcalendarHelper.createFile(calendar, path)
file.write(calendar_string)
end
end

# TODO allow updating a calendar file, to preserve uids.
# This enables the calendar client to recognise which events are new
end

0 comments on commit 5377320

Please sign in to comment.