Skip to content

Commit 56bc222

Browse files
authored
Merge pull request #27 from interflux-electronics/feature/event-registrations
Event registrations
2 parents 88b4791 + 8f54381 commit 56bc222

18 files changed

+304
-39
lines changed

app/controllers/concerns/json_api_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def forbidden_filters
391391
# allow_create
392392
# end
393393
#
394-
def allow_create(controller_attributes: nil)
394+
def allow_create(controller_attributes = nil)
395395
hash = strong_attributes
396396
.merge(strong_relationships)
397397
.merge(controller_attributes)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module V1
2+
module Admin
3+
class EventAttendeesController < ApplicationController
4+
def index
5+
allow_index
6+
end
7+
8+
def show
9+
allow_show
10+
end
11+
12+
def create
13+
forbidden
14+
end
15+
16+
def update
17+
forbidden
18+
end
19+
20+
def destroy
21+
forbidden
22+
end
23+
24+
private
25+
26+
def model_class
27+
EventAttendee
28+
end
29+
30+
def serializer_class
31+
V1::Admin::EventAttendeeSerializer
32+
end
33+
end
34+
end
35+
end

app/controllers/v1/admin/events_controller.rb

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def creatable_attributes
3939
start_date
4040
end_date
4141
description
42+
has_registration_form
43+
ask_first_name
44+
ask_last_name
45+
ask_role
46+
ask_company
47+
confirmation_email_subject
48+
confirmation_email_body
49+
confirmation_email_bcc
4250
]
4351
end
4452

@@ -51,6 +59,8 @@ def creatable_relationships
5159
def permitted_includes
5260
%i[
5361
country
62+
permalinks
63+
event_attendees
5464
]
5565
end
5666
end

app/controllers/v1/admin/permalinks_controller.rb

+29-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ def show
1010
end
1111

1212
def create
13-
allow_create
13+
allow_create(
14+
{
15+
slug: unique_slug
16+
}
17+
)
1418
end
1519

1620
def update
@@ -39,11 +43,35 @@ def creatable_attributes
3943
]
4044
end
4145

46+
def creatable_relationships
47+
%i[
48+
event
49+
]
50+
end
51+
4252
def permitted_filters
4353
%i[
4454
slug
4555
]
4656
end
57+
58+
def unique_slug
59+
slug = nil
60+
unique = false
61+
62+
until slug.present? && unique
63+
slug = three_random_letters
64+
record = Permalink.find_by slug: slug
65+
unique = record.nil?
66+
end
67+
68+
slug
69+
end
70+
71+
def three_random_letters
72+
charset = Array('A'..'Z') + Array('a'..'z')
73+
Array.new(3) { charset.sample }.join
74+
end
4775
end
4876
end
4977
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module V1
2+
module Public
3+
class EventAttendeesController < ApplicationController
4+
def index
5+
forbidden
6+
end
7+
8+
def show
9+
forbidden
10+
end
11+
12+
def create
13+
allow_create
14+
end
15+
16+
def update
17+
allow_update
18+
end
19+
20+
def destroy
21+
forbidden
22+
end
23+
24+
private
25+
26+
def model_class
27+
EventAttendee
28+
end
29+
30+
def serializer_class
31+
V1::Public::EventAttendeeSerializer
32+
end
33+
34+
def creatable_attributes
35+
%i[
36+
first_name
37+
last_name
38+
role
39+
company
40+
email
41+
]
42+
end
43+
44+
def creatable_relationships
45+
%i[
46+
event
47+
]
48+
end
49+
end
50+
end
51+
end

app/models/event.rb

+23-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22
#
33
# Table name: events
44
#
5-
# id :uuid not null, primary key
6-
# city :string
7-
# dates :string
8-
# description :string
9-
# end_date :string
10-
# name :string
11-
# start_date :string
12-
# created_at :datetime not null
13-
# updated_at :datetime not null
14-
# country_id :string
5+
# id :uuid not null, primary key
6+
# ask_company :boolean
7+
# ask_first_name :boolean
8+
# ask_last_name :boolean
9+
# ask_role :boolean
10+
# city :string
11+
# confirmation_email_bcc :string default("s.teliszewski@interflux.com, jw@interflux.au")
12+
# confirmation_email_body :string default("Hello {first_name} {last_name}, We look forward seeing you at {event_name} on {event_date} in {event_location}. Best regards, The Interflux Electronics team")
13+
# confirmation_email_subject :string default("See you soon at {event_name}!")
14+
# dates :string
15+
# description :string
16+
# end_date :string
17+
# has_registration_form :boolean
18+
# name :string
19+
# start_date :string
20+
# created_at :datetime not null
21+
# updated_at :datetime not null
22+
# country_id :string
1523
#
1624
class Event < ApplicationRecord
1725
belongs_to :country
26+
27+
has_many :permalinks
28+
has_many :event_attendees
29+
30+
alias_attribute :attendees, :event_attendees
1831
end

app/models/event_attendee.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# == Schema Information
2+
#
3+
# Table name: event_attendees
4+
#
5+
# id :uuid not null, primary key
6+
# company :string
7+
# email :string
8+
# first_name :string
9+
# last_name :string
10+
# role :string
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
# event_id :uuid
14+
# person_id :uuid
15+
#
16+
class EventAttendee < ApplicationRecord
17+
belongs_to :event
18+
belongs_to :person, optional: true
19+
end

app/models/permalink.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
# notes :string
77
# redirect_to :string
88
# slug :string
9+
# event_id :uuid
10+
#
11+
# Indexes
12+
#
13+
# index_permalinks_on_slug (slug) UNIQUE
914
#
1015
class Permalink < ApplicationRecord
11-
# attr :redirect_from
12-
# attr :redirect_to
13-
# attr :notes
16+
belongs_to :event, optional: true
17+
18+
validates :slug, presence: true, uniqueness: true
1419
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module V1
2+
module Admin
3+
class EventAttendeeSerializer < ApplicationSerializer
4+
attributes :first_name,
5+
:last_name,
6+
:role,
7+
:company,
8+
:email
9+
10+
belongs_to :event
11+
belongs_to :person
12+
end
13+
end
14+
end

app/serializers/v1/admin/event_serializer.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ class EventSerializer < ApplicationSerializer
66
:dates,
77
:start_date,
88
:end_date,
9-
:description
9+
:description,
10+
:has_registration_form,
11+
:ask_first_name,
12+
:ask_last_name,
13+
:ask_role,
14+
:ask_company,
15+
:confirmation_email_subject,
16+
:confirmation_email_body,
17+
:confirmation_email_bcc
1018

1119
belongs_to :country
20+
21+
has_many :event_attendees
22+
has_many :permalinks
1223
end
1324
end
1425
end

app/serializers/v1/admin/permalink_serializer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class PermalinkSerializer < ApplicationSerializer
44
attributes :slug,
55
:redirect_to,
66
:notes
7+
8+
belongs_to :event
79
end
810
end
911
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module V1
2+
module Public
3+
class EventAttendeeSerializer < ApplicationSerializer
4+
attributes :first_name,
5+
:last_name,
6+
:role,
7+
:company,
8+
:email
9+
10+
belongs_to :event
11+
end
12+
end
13+
end

app/serializers/v1/public/event_serializer.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ class EventSerializer < ApplicationSerializer
66
:dates,
77
:start_date,
88
:end_date,
9-
:description
9+
:description,
10+
:has_registration_form,
11+
:ask_first_name,
12+
:ask_last_name,
13+
:ask_role,
14+
:ask_company
1015

1116
belongs_to :country
1217
end

config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
resources :document_categories, path: '/document-categories'
2727
resources :documents
2828
resources :events
29+
resources :event_attendees, path: '/event-attendees'
2930
resources :features
3031
resources :images
3132
resources :languages
@@ -69,6 +70,7 @@
6970
resources :document_categories, path: '/document-categories'
7071
resources :documents
7172
resources :events
73+
resources :event_attendees, path: '/event-attendees'
7274
resources :features
7375
resources :images
7476
resources :languages
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class CreateEventAttendees < ActiveRecord::Migration[6.1]
2+
def change
3+
change_table :events, bulk: true do |t|
4+
t.column :has_registration_form, :boolean
5+
6+
t.column :ask_first_name, :boolean
7+
t.column :ask_last_name, :boolean
8+
t.column :ask_role, :boolean
9+
t.column :ask_company, :boolean
10+
11+
t.column :confirmation_email_subject, :string, default: 'See you soon at {event_name}!'
12+
t.column :confirmation_email_body, :string, default: 'Hello {first_name} {last_name}, We look forward seeing you at {event_name} on {event_date} in {event_location}. Best regards, The Interflux Electronics team'
13+
t.column :confirmation_email_bcc, :string, default: 's.teliszewski@interflux.com, jw@interflux.au'
14+
end
15+
16+
change_table :permalinks, bulk: true do |t|
17+
t.column :event_id, :uuid
18+
end
19+
20+
create_table :event_attendees, id: :uuid do |t|
21+
t.uuid :event_id
22+
t.uuid :person_id
23+
24+
t.string :first_name
25+
t.string :last_name
26+
t.string :role
27+
t.string :company
28+
t.string :email
29+
30+
t.timestamps
31+
end
32+
end
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUniqueConstraintsToPermalinks < ActiveRecord::Migration[6.1]
2+
def change
3+
add_index :permalinks, :slug, unique: true
4+
end
5+
end

0 commit comments

Comments
 (0)