mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 15:52:09 +00:00
fix: refactored the codebase
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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
|
||||
&& $existingPlayer->inactive_at === null
|
||||
) {
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user