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
This commit is contained in:
parent
75862aec03
commit
de72d21e24
4 changed files with 43 additions and 2 deletions
|
|
@ -26,6 +26,15 @@ module Api
|
||||||
phantom.gw_individual_scores.count
|
phantom.gw_individual_scores.count
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
20
app/controllers/api/v1/phantom_claims_controller.rb
Normal file
20
app/controllers/api/v1/phantom_claims_controller.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -7,9 +7,9 @@ module Api
|
||||||
|
|
||||||
before_action :restrict_access
|
before_action :restrict_access
|
||||||
before_action :set_crew
|
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 :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
|
# GET /crews/:crew_id/phantom_players
|
||||||
def index
|
def index
|
||||||
|
|
@ -78,6 +78,14 @@ module Api
|
||||||
render json: PhantomPlayerBlueprint.render(@phantom, view: :with_claimed_by, root: :phantom_player)
|
render json: PhantomPlayerBlueprint.render(@phantom, view: :with_claimed_by, root: :phantom_player)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def set_crew
|
def set_crew
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@ Rails.application.routes.draw do
|
||||||
member do
|
member do
|
||||||
post :assign
|
post :assign
|
||||||
post :confirm_claim
|
post :confirm_claim
|
||||||
|
post :decline_claim
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -212,6 +213,9 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
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)
|
# GW Events (public read, admin write)
|
||||||
resources :gw_events, only: %i[index show create update] do
|
resources :gw_events, only: %i[index show create update] do
|
||||||
member do
|
member do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue