From de72d21e24705a62e3f00906739a8ebc95e929bb Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 17 Dec 2025 18:28:23 -0800 Subject: [PATCH] add decline/pending endpoints for phantom claims - decline_claim action lets assigned user reject assignment - pending_phantom_claims endpoint for user's pending claims - with_crew blueprint view for phantom claims context --- .../api/v1/phantom_player_blueprint.rb | 9 +++++++++ .../api/v1/phantom_claims_controller.rb | 20 +++++++++++++++++++ .../api/v1/phantom_players_controller.rb | 12 +++++++++-- config/routes.rb | 4 ++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/phantom_claims_controller.rb diff --git a/app/blueprints/api/v1/phantom_player_blueprint.rb b/app/blueprints/api/v1/phantom_player_blueprint.rb index 4cfc529..6efa755 100644 --- a/app/blueprints/api/v1/phantom_player_blueprint.rb +++ b/app/blueprints/api/v1/phantom_player_blueprint.rb @@ -26,6 +26,15 @@ module Api phantom.gw_individual_scores.count end end + + # Used for pending phantom claims - includes crew info for context + view :with_crew do + include_view :with_claimed_by + + field :crew do |phantom| + phantom.crew ? CrewBlueprint.render_as_hash(phantom.crew, view: :minimal) : nil + end + end end end end diff --git a/app/controllers/api/v1/phantom_claims_controller.rb b/app/controllers/api/v1/phantom_claims_controller.rb new file mode 100644 index 0000000..1e8320a --- /dev/null +++ b/app/controllers/api/v1/phantom_claims_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Api + module V1 + class PhantomClaimsController < Api::V1::ApiController + before_action :restrict_access + + # GET /pending_phantom_claims + # Returns phantom players assigned to the current user that are pending confirmation + def index + phantoms = PhantomPlayer + .includes(:crew, :claimed_by) + .where(claimed_by: current_user, claim_confirmed: false) + .order(created_at: :desc) + + render json: PhantomPlayerBlueprint.render(phantoms, view: :with_crew, root: :phantom_claims) + end + end + end +end diff --git a/app/controllers/api/v1/phantom_players_controller.rb b/app/controllers/api/v1/phantom_players_controller.rb index b7b2811..323a1a4 100644 --- a/app/controllers/api/v1/phantom_players_controller.rb +++ b/app/controllers/api/v1/phantom_players_controller.rb @@ -7,9 +7,9 @@ module Api before_action :restrict_access before_action :set_crew - before_action :authorize_crew_member!, only: %i[index confirm_claim] + before_action :authorize_crew_member!, only: %i[index confirm_claim decline_claim] 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] + before_action :set_phantom, only: %i[show update destroy assign confirm_claim decline_claim] # GET /crews/:crew_id/phantom_players def index @@ -78,6 +78,14 @@ module Api render json: PhantomPlayerBlueprint.render(@phantom, view: :with_claimed_by, root: :phantom_player) end + # POST /crews/:crew_id/phantom_players/:id/decline_claim + def decline_claim + raise CrewErrors::NotClaimedByUserError unless @phantom.claimed_by == current_user + + @phantom.unassign! + render json: PhantomPlayerBlueprint.render(@phantom, view: :with_claimed_by, root: :phantom_player) + end + private def set_crew diff --git a/config/routes.rb b/config/routes.rb index 3b670af..53544fa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -197,6 +197,7 @@ Rails.application.routes.draw do member do post :assign post :confirm_claim + post :decline_claim end end end @@ -212,6 +213,9 @@ Rails.application.routes.draw do end end + # Pending phantom claims for current user (outside crew context) + get :pending_phantom_claims, to: 'phantom_claims#index' + # GW Events (public read, admin write) resources :gw_events, only: %i[index show create update] do member do