Define a controller for invitations
Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 57s
Run unit tests / check-licenses (pull_request) Failing after 2m13s
Run unit tests / rubocop (pull_request) Failing after 3m35s
Run unit tests / unit_tests (pull_request) Failing after 5m6s
Run unit tests / build-static-assets (pull_request) Has been skipped
Some checks failed
Run unit tests / copyright_notice (pull_request) Successful in 57s
Run unit tests / check-licenses (pull_request) Failing after 2m13s
Run unit tests / rubocop (pull_request) Failing after 3m35s
Run unit tests / unit_tests (pull_request) Failing after 5m6s
Run unit tests / build-static-assets (pull_request) Has been skipped
This commit is contained in:
parent
3e6afcc048
commit
5fb26f42d6
1
.gitignore
vendored
1
.gitignore
vendored
@ -36,3 +36,4 @@
|
|||||||
|
|
||||||
# Ignore swagger generated documentation
|
# Ignore swagger generated documentation
|
||||||
swagger/v1/swagger.yaml
|
swagger/v1/swagger.yaml
|
||||||
|
wedding-planner.code-workspace
|
||||||
|
42
app/controllers/invitations_controller.rb
Normal file
42
app/controllers/invitations_controller.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
class InvitationsController < ApplicationController
|
||||||
|
def index
|
||||||
|
render json: Invitation.includes(:guests).as_json(
|
||||||
|
only: :id,
|
||||||
|
include: {
|
||||||
|
guests: {
|
||||||
|
only: %i[id name]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
invitation = Invitation.create
|
||||||
|
|
||||||
|
if invitation.persisted?
|
||||||
|
render json: invitation, only: :id, status: :created
|
||||||
|
else
|
||||||
|
render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
invitation = Invitation.find(params[:id])
|
||||||
|
|
||||||
|
if invitation.update(guest_ids: params[:invitation][:guest_ids])
|
||||||
|
render json: invitation, only: :id, include: { guests: { only: %i[id name] } }, status: :ok
|
||||||
|
else
|
||||||
|
render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
invitation = Invitation.find(params[:id])
|
||||||
|
|
||||||
|
if invitation.destroy
|
||||||
|
head :no_content
|
||||||
|
else
|
||||||
|
render json: { errors: invitation.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -21,4 +21,6 @@ class Wedding < ApplicationRecord
|
|||||||
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
|
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
|
||||||
|
|
||||||
has_many :guests, dependent: :delete_all
|
has_many :guests, dependent: :delete_all
|
||||||
|
has_many :groups, dependent: :delete_all
|
||||||
|
has_many :invitations, dependent: :delete_all
|
||||||
end
|
end
|
||||||
|
@ -39,6 +39,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
resources :tables_arrangements, only: %i[index show create]
|
resources :tables_arrangements, only: %i[index show create]
|
||||||
resources :summary, only: :index
|
resources :summary, only: :index
|
||||||
|
resources :invitations, only: %i[index create update destroy]
|
||||||
|
|
||||||
root to: redirect("/%{slug}")
|
root to: redirect("/%{slug}")
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
NUMBER_OF_GUESTS = 200
|
NUMBER_OF_GUESTS = 200
|
||||||
|
|
||||||
ActsAsTenant.without_tenant do
|
ActsAsTenant.without_tenant do
|
||||||
|
GroupAffinity.delete_all
|
||||||
Wedding.delete_all
|
Wedding.delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -78,6 +79,8 @@ ActsAsTenant.with_tenant(wedding) do
|
|||||||
guests.shift(rand(1..3)).each do |guest|
|
guests.shift(rand(1..3)).each do |guest|
|
||||||
guest.update!(invitation:)
|
guest.update!(invitation:)
|
||||||
end
|
end
|
||||||
|
guests.shift(1) if rand < 0.3 # Leave a percentage of guests without an invitation
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user