Skip to content

Commit a1b36af

Browse files
committed
feat: implement hire from scouting
1 parent 0a067c3 commit a1b36af

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

app/modules/players/services/roster_management_service.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ def self.hire_from_scouting(scouting_target:, organization:, contract_start:, co
8080
previous_organization_id: nil
8181
)
8282

83-
# Update watchlist status to signed
83+
# Remove from org's watchlist — player is now on the roster
8484
watchlist = scouting_target.scouting_watchlists.find_by(organization: organization)
85-
watchlist&.update!(status: 'signed')
85+
watchlist&.destroy
86+
87+
# Clean up the global target if no other org is watching it
88+
scouting_target.destroy if scouting_target.scouting_watchlists.none?
8689

8790
# Log the action
8891
log_roster_addition(player, scouting_target, current_user)

app/modules/scouting/controllers/players_controller.rb

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Controllers
55
# Scouting Players Controller
66
# Manages GLOBAL scouting targets and org-specific watchlists
77
class PlayersController < Api::V1::BaseController
8-
before_action :set_scouting_target, only: %i[show update destroy sync]
8+
before_action :set_scouting_target, only: %i[show update destroy sync import_to_roster]
9+
before_action :require_management!, only: %i[import_to_roster]
910

1011
# GET /api/v1/scouting/players
1112
# Returns global scouting targets with optional watchlist filtering
@@ -104,6 +105,32 @@ def destroy
104105
render_deleted(message: 'Removed from watchlist')
105106
end
106107

108+
# POST /api/v1/scouting/players/:id/import_to_roster
109+
# Hires the scouting target directly to the roster and removes them from scouting
110+
def import_to_roster
111+
result = RosterManagementService.hire_from_scouting(
112+
scouting_target: @target,
113+
organization: current_organization,
114+
contract_start: params[:contract_start].present? ? Date.parse(params[:contract_start]) : nil,
115+
contract_end: params[:contract_end].present? ? Date.parse(params[:contract_end]) : nil,
116+
salary: params[:salary]&.to_d,
117+
jersey_number: params[:jersey_number]&.to_i,
118+
current_user: current_user
119+
)
120+
121+
if result[:success]
122+
render_created(
123+
{ player: PlayerSerializer.render_as_hash(result[:player]) },
124+
message: result[:message]
125+
)
126+
else
127+
render_error(message: result[:error], code: result[:code], status: :unprocessable_entity)
128+
end
129+
rescue ArgumentError
130+
render_error(message: 'Invalid date format. Use YYYY-MM-DD', code: 'INVALID_DATE_FORMAT',
131+
status: :unprocessable_entity)
132+
end
133+
107134
def sync
108135
unless @target.riot_puuid.present?
109136
return render_error(
@@ -123,6 +150,16 @@ def sync
123150

124151
private
125152

153+
def require_management!
154+
return if %w[admin owner].include?(current_user.role)
155+
156+
render_error(
157+
message: 'Only owners and admins can import players to the roster',
158+
code: 'FORBIDDEN',
159+
status: :forbidden
160+
)
161+
end
162+
126163
def create_watchlist_for(target)
127164
target.scouting_watchlists.create!(
128165
organization: current_organization,

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
resources :players, controller: '/scouting/controllers/players' do
202202
member do
203203
post :sync
204+
post :import_to_roster
204205
end
205206
end
206207
get 'regions', to: '/scouting/controllers/regions#index'

0 commit comments

Comments
 (0)