add bulk_create endpoint for phantom players

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-12-13 23:33:49 -08:00
parent fb253adf45
commit f4ef04881e
2 changed files with 25 additions and 1 deletions

View file

@ -8,7 +8,7 @@ module Api
before_action :restrict_access
before_action :set_crew
before_action :authorize_crew_member!, only: %i[index confirm_claim]
before_action :authorize_crew_officer!, only: %i[create update destroy assign]
before_action :authorize_crew_officer!, only: %i[create bulk_create update destroy assign]
before_action :set_phantom, only: %i[show update destroy assign confirm_claim]
# GET /crews/:crew_id/phantom_players
@ -33,6 +33,23 @@ module Api
end
end
# POST /crews/:crew_id/phantom_players/bulk_create
def bulk_create
phantoms = []
ActiveRecord::Base.transaction do
bulk_params[:phantom_players].each do |phantom_attrs|
phantom = @crew.phantom_players.build(phantom_attrs.permit(:name, :granblue_id, :notes, :joined_at))
phantom.save!
phantoms << phantom
end
end
render json: PhantomPlayerBlueprint.render(phantoms, root: :phantom_players), status: :created
rescue ActiveRecord::RecordInvalid => e
render json: { errors: e.record.errors.full_messages }, status: :unprocessable_entity
end
# PUT /crews/:crew_id/phantom_players/:id
def update
if @phantom.update(phantom_params)
@ -74,6 +91,10 @@ module Api
def phantom_params
params.require(:phantom_player).permit(:name, :granblue_id, :notes, :joined_at)
end
def bulk_params
params.permit(phantom_players: %i[name granblue_id notes joined_at])
end
end
end
end

View file

@ -182,6 +182,9 @@ Rails.application.routes.draw do
resources :invitations, controller: 'crew_invitations', only: %i[index create]
resources :phantom_players, only: %i[index show create update destroy] do
collection do
post :bulk_create
end
member do
post :assign
post :confirm_claim