Skip to content

Commit

Permalink
Update node selection to also filter location
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoJF committed Oct 7, 2020
1 parent 3c8e0a8 commit aa7d96f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/User/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions app/Services/User/NodeSelectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit aa7d96f

Please sign in to comment.