mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 18:12:09 +00:00
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Resources\ClosedRoomResource;
|
|
use App\Models\Player;
|
|
use App\Services\Rooms\RoomParticipationService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class RoomJoinController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly RoomParticipationService $roomParticipation,
|
|
) {}
|
|
|
|
public function __invoke(Request $request): Response|RedirectResponse
|
|
{
|
|
$joinCode = strtoupper(trim((string) $request->query('join_code')));
|
|
$room = $this->roomParticipation->findByJoinCode($joinCode);
|
|
$existingPlayer = $room !== null
|
|
? $this->roomParticipation->findExistingPlayer(
|
|
$room,
|
|
$request->user(),
|
|
$request->session()->get("room_players.{$room->id}"),
|
|
)
|
|
: null;
|
|
|
|
if (
|
|
$room !== null
|
|
&& ! $room->isClosed()
|
|
&& $existingPlayer instanceof Player
|
|
) {
|
|
return to_route('room.show', $room);
|
|
}
|
|
|
|
return Inertia::render('rooms/Join', [
|
|
'join_code' => $joinCode,
|
|
'defaultPlayerName' => $existingPlayer instanceof Player
|
|
? $existingPlayer->name
|
|
: $request->user()?->name,
|
|
'closedRoom' => $room?->isClosed()
|
|
? (new ClosedRoomResource($room))->resolve($request)
|
|
: null,
|
|
]);
|
|
}
|
|
}
|