diff --git a/app/Http/Controllers/User/ServerController.php b/app/Http/Controllers/User/ServerController.php index cc3928b..7b6a325 100644 --- a/app/Http/Controllers/User/ServerController.php +++ b/app/Http/Controllers/User/ServerController.php @@ -43,7 +43,6 @@ public function store( Request $request ): ServerResource { $game = Game::findOrFail($request->input('game')); - // TODO: we are not using the location for nodeSelection $location = Location::findOrFail($request->input('location')); $processor = $gameService->getProcessor($game); @@ -53,7 +52,7 @@ public function store( // Selects node to create the server on // TODO: this should come from request - $node = $nodeSelection->handle($game); + $node = $nodeSelection->handle($location, $game); // Transform user form to server cost $cost = $configurerService->formToCost($game, $node, $form); diff --git a/app/Services/User/NodeSelectionService.php b/app/Services/User/NodeSelectionService.php index 4a9d48f..a45d84d 100644 --- a/app/Services/User/NodeSelectionService.php +++ b/app/Services/User/NodeSelectionService.php @@ -3,12 +3,13 @@ namespace App\Services\User; use App\Game; +use App\Location; use App\Node; class NodeSelectionService { - public function handle(Game $game): Node + public function handle(Location $location, Game $game): Node { - return $game->nodes()->inRandomOrder()->first(); + return $game->nodes()->where('location_id', $location->id)->inRandomOrder()->first(); } }