@@ -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 ,
0 commit comments