Skip to content

Commit

Permalink
feat: switched from using an hash to a calendar_id
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed May 21, 2024
1 parent e91ef4f commit 78378d0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show
end

def create_calendar
@member = Member.find(params[:hash])
@member = Member.find_by(calendar_id: params[:calendar_id])
events = @member.activities.map { |a| IcalendarHelper.activityToEvent(a) }
IcalendarHelper.createCalendar(events).to_ical
end
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
get 'calendar/:hash', to: 'calendars#show', defaults: { format: 'ics' }
get 'calendar/:calendar_id', to: 'calendars#show', defaults: { format: 'ics' }

use_doorkeeper_openid_connect

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240521180025_add_calendar_id_to_member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCalendarIdToMember < ActiveRecord::Migration[6.1]
def change
add_column :members, :calendar_id, :uuid
end
end
3 changes: 2 additions & 1 deletion db/seeds/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
student_id: "F#{ Faker::Number.number(digits: 6) }",
birth_date: Faker::Date.between(from: 28.years.ago, to: 16.years.ago),
join_date: Faker::Date.between(from: 6.years.ago, to: Date.today),
comments: (Faker::Boolean.boolean(true_ratio: 0.3) ? Faker::Hacker.say_something_smart : nil)
comments: (Faker::Boolean.boolean(true_ratio: 0.3) ? Faker::Hacker.say_something_smart : nil),
calendar_id: Faker::Boolean.boolean(true_ratio: 0.4) ? SecureRandom.uuid : nil
)

puts(" -> #{ member.name } (#{ member.student_id })")
Expand Down
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ CREATE TABLE public.members (
consent integer DEFAULT 0,
consent_at date,
created_at timestamp without time zone,
updated_at timestamp without time zone
updated_at timestamp without time zone,
calendar_id uuid
);


Expand Down Expand Up @@ -1736,6 +1737,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220221195220'),
('20220406092056'),
('20220524203723'),
('20240125003700');
('20240125003700'),
('20240521180025');


2 changes: 1 addition & 1 deletion lib/icalendar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def IcalendarHelper.activityToEvent(activity)
event.dtstart = activity.start_date
event.dtend = activity.end_date
event.summary = activity.name
event.description = activity.description_nl
event.description = activity.description_nl # TODO localise
event.location = activity.location
return event
end
Expand Down

0 comments on commit 78378d0

Please sign in to comment.