From f4ef04881e12945b08e8ab8b03241d981b00d8f1 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 13 Dec 2025 23:33:49 -0800 Subject: [PATCH] add bulk_create endpoint for phantom players Co-Authored-By: Claude Opus 4.5 --- .../api/v1/phantom_players_controller.rb | 23 ++++++++++++++++++- config/routes.rb | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/phantom_players_controller.rb b/app/controllers/api/v1/phantom_players_controller.rb index 2d00771..dde61ba 100644 --- a/app/controllers/api/v1/phantom_players_controller.rb +++ b/app/controllers/api/v1/phantom_players_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 5d6aedb..227488b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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