-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'guest registration' and an endpoint to get current event data.
- Loading branch information
Showing
11 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AddEventToResponse::V20240905074157 < Avram::Migrator::Migration::V1 | ||
def migrate | ||
alter table_for(Response) do | ||
add_belongs_to event : Event, on_delete: :cascade | ||
end | ||
end | ||
|
||
def rollback | ||
alter table_for(Response) do | ||
remove :event | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
class Api::Event::Create < ApiAction | ||
post "/api/events" do | ||
post "/api/events/" do | ||
serialized_event = EventCreateSerializer.from_json(params.body) | ||
event = SaveEvent.create!(serialized_event) | ||
json EventSerializer.new(event) | ||
end | ||
end | ||
|
||
class Api::Event::Get < ApiAction | ||
get "/api/events/:event_uuid" do | ||
event = EventQuery.new.preload_slots.preload_responses.event_uuid(event_uuid).first | ||
json EventDetailSerializer.new(event) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Api::Guest::Create < ApiAction | ||
post "/api/events/:event_uuid/guest" do | ||
event = EventQuery.new.event_uuid(event_uuid).first | ||
guest_data = GuestCreateSerializer.from_json(params.body) | ||
guest = SaveGuest.create!(guest_data, event_id: event.id) | ||
json({guest_id: guest.id}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class SaveGuest < Guest::SaveOperation | ||
# To save user provided params to the database, you must permit them | ||
# https://luckyframework.org/guides/database/saving-records#perma-permitting-columns | ||
# | ||
# permit_columns column_1, column_2 | ||
needs serialized_guest : GuestCreateSerializer | ||
|
||
before_save do | ||
name.value = serialized_guest.name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class GuestSerializer < BaseSerializer | ||
def initialize(@guest : Guest) | ||
end | ||
|
||
def render | ||
{ | ||
name: @guest.name | ||
} | ||
end | ||
end | ||
|
||
class GuestCreateSerializer | ||
include JSON::Serializable | ||
property name : String | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
class ResponseSerializer < BaseSerializer | ||
def initialize(@response : Response) | ||
end | ||
def render | ||
{ | ||
response: @response.response, | ||
guest: GuestSerializer.new(@response.guest) | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters