mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 19:32:09 +00:00
35 lines
954 B
PHP
35 lines
954 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\JoinRoomRequest;
|
|
use App\Services\Rooms\RoomParticipationService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class RoomPlayerController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly RoomParticipationService $roomParticipation,
|
|
) {}
|
|
|
|
public function join(JoinRoomRequest $request): RedirectResponse
|
|
{
|
|
/** @var array{join_code: string, player_name: string} $validated */
|
|
$validated = $request->validated();
|
|
$sessionPlayerIds = $request->session()->get('room_players', []);
|
|
|
|
[$room, $player] = $this->roomParticipation->join(
|
|
$validated,
|
|
$request->user(),
|
|
is_array($sessionPlayerIds) ? $sessionPlayerIds : [],
|
|
);
|
|
|
|
$request->session()->put(
|
|
"room_players.{$room->id}",
|
|
$player->id,
|
|
);
|
|
|
|
return to_route('room.show', $room);
|
|
}
|
|
}
|