Skip to content

Commit

Permalink
Merge pull request #27 from interflux-electronics/feature/event-regis…
Browse files Browse the repository at this point in the history
…trations

Event registrations
  • Loading branch information
janwerkhoven authored Apr 7, 2024
2 parents 88b4791 + 8f54381 commit 56bc222
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/json_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def forbidden_filters
# allow_create
# end
#
def allow_create(controller_attributes: nil)
def allow_create(controller_attributes = nil)
hash = strong_attributes
.merge(strong_relationships)
.merge(controller_attributes)
Expand Down
35 changes: 35 additions & 0 deletions app/controllers/v1/admin/event_attendees_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module V1
module Admin
class EventAttendeesController < ApplicationController
def index
allow_index
end

def show
allow_show
end

def create
forbidden
end

def update
forbidden
end

def destroy
forbidden
end

private

def model_class
EventAttendee
end

def serializer_class
V1::Admin::EventAttendeeSerializer
end
end
end
end
10 changes: 10 additions & 0 deletions app/controllers/v1/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def creatable_attributes
start_date
end_date
description
has_registration_form
ask_first_name
ask_last_name
ask_role
ask_company
confirmation_email_subject
confirmation_email_body
confirmation_email_bcc
]
end

Expand All @@ -51,6 +59,8 @@ def creatable_relationships
def permitted_includes
%i[
country
permalinks
event_attendees
]
end
end
Expand Down
30 changes: 29 additions & 1 deletion app/controllers/v1/admin/permalinks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def show
end

def create
allow_create
allow_create(
{
slug: unique_slug
}
)
end

def update
Expand Down Expand Up @@ -39,11 +43,35 @@ def creatable_attributes
]
end

def creatable_relationships
%i[
event
]
end

def permitted_filters
%i[
slug
]
end

def unique_slug
slug = nil
unique = false

until slug.present? && unique
slug = three_random_letters
record = Permalink.find_by slug: slug
unique = record.nil?
end

slug
end

def three_random_letters
charset = Array('A'..'Z') + Array('a'..'z')
Array.new(3) { charset.sample }.join
end
end
end
end
51 changes: 51 additions & 0 deletions app/controllers/v1/public/event_attendees_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module V1
module Public
class EventAttendeesController < ApplicationController
def index
forbidden
end

def show
forbidden
end

def create
allow_create
end

def update
allow_update
end

def destroy
forbidden
end

private

def model_class
EventAttendee
end

def serializer_class
V1::Public::EventAttendeeSerializer
end

def creatable_attributes
%i[
first_name
last_name
role
company
email
]
end

def creatable_relationships
%i[
event
]
end
end
end
end
33 changes: 23 additions & 10 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
#
# Table name: events
#
# id :uuid not null, primary key
# city :string
# dates :string
# description :string
# end_date :string
# name :string
# start_date :string
# created_at :datetime not null
# updated_at :datetime not null
# country_id :string
# id :uuid not null, primary key
# ask_company :boolean
# ask_first_name :boolean
# ask_last_name :boolean
# ask_role :boolean
# city :string
# confirmation_email_bcc :string default("[email protected], [email protected]")
# 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")
# confirmation_email_subject :string default("See you soon at {event_name}!")
# dates :string
# description :string
# end_date :string
# has_registration_form :boolean
# name :string
# start_date :string
# created_at :datetime not null
# updated_at :datetime not null
# country_id :string
#
class Event < ApplicationRecord
belongs_to :country

has_many :permalinks
has_many :event_attendees

alias_attribute :attendees, :event_attendees
end
19 changes: 19 additions & 0 deletions app/models/event_attendee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: event_attendees
#
# id :uuid not null, primary key
# company :string
# email :string
# first_name :string
# last_name :string
# role :string
# created_at :datetime not null
# updated_at :datetime not null
# event_id :uuid
# person_id :uuid
#
class EventAttendee < ApplicationRecord
belongs_to :event
belongs_to :person, optional: true
end
11 changes: 8 additions & 3 deletions app/models/permalink.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
# notes :string
# redirect_to :string
# slug :string
# event_id :uuid
#
# Indexes
#
# index_permalinks_on_slug (slug) UNIQUE
#
class Permalink < ApplicationRecord
# attr :redirect_from
# attr :redirect_to
# attr :notes
belongs_to :event, optional: true

validates :slug, presence: true, uniqueness: true
end
14 changes: 14 additions & 0 deletions app/serializers/v1/admin/event_attendee_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module V1
module Admin
class EventAttendeeSerializer < ApplicationSerializer
attributes :first_name,
:last_name,
:role,
:company,
:email

belongs_to :event
belongs_to :person
end
end
end
13 changes: 12 additions & 1 deletion app/serializers/v1/admin/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ class EventSerializer < ApplicationSerializer
:dates,
:start_date,
:end_date,
:description
:description,
:has_registration_form,
:ask_first_name,
:ask_last_name,
:ask_role,
:ask_company,
:confirmation_email_subject,
:confirmation_email_body,
:confirmation_email_bcc

belongs_to :country

has_many :event_attendees
has_many :permalinks
end
end
end
2 changes: 2 additions & 0 deletions app/serializers/v1/admin/permalink_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class PermalinkSerializer < ApplicationSerializer
attributes :slug,
:redirect_to,
:notes

belongs_to :event
end
end
end
13 changes: 13 additions & 0 deletions app/serializers/v1/public/event_attendee_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module V1
module Public
class EventAttendeeSerializer < ApplicationSerializer
attributes :first_name,
:last_name,
:role,
:company,
:email

belongs_to :event
end
end
end
7 changes: 6 additions & 1 deletion app/serializers/v1/public/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ class EventSerializer < ApplicationSerializer
:dates,
:start_date,
:end_date,
:description
:description,
:has_registration_form,
:ask_first_name,
:ask_last_name,
:ask_role,
:ask_company

belongs_to :country
end
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
resources :document_categories, path: '/document-categories'
resources :documents
resources :events
resources :event_attendees, path: '/event-attendees'
resources :features
resources :images
resources :languages
Expand Down Expand Up @@ -69,6 +70,7 @@
resources :document_categories, path: '/document-categories'
resources :documents
resources :events
resources :event_attendees, path: '/event-attendees'
resources :features
resources :images
resources :languages
Expand Down
33 changes: 33 additions & 0 deletions db/migrate/20240406020528_create_event_attendees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class CreateEventAttendees < ActiveRecord::Migration[6.1]
def change
change_table :events, bulk: true do |t|
t.column :has_registration_form, :boolean

t.column :ask_first_name, :boolean
t.column :ask_last_name, :boolean
t.column :ask_role, :boolean
t.column :ask_company, :boolean

t.column :confirmation_email_subject, :string, default: 'See you soon at {event_name}!'
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'
t.column :confirmation_email_bcc, :string, default: '[email protected], [email protected]'
end

change_table :permalinks, bulk: true do |t|
t.column :event_id, :uuid
end

create_table :event_attendees, id: :uuid do |t|
t.uuid :event_id
t.uuid :person_id

t.string :first_name
t.string :last_name
t.string :role
t.string :company
t.string :email

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUniqueConstraintsToPermalinks < ActiveRecord::Migration[6.1]
def change
add_index :permalinks, :slug, unique: true
end
end
Loading

0 comments on commit 56bc222

Please sign in to comment.