fix: refactored the codebase

This commit is contained in:
2026-08-20 23:00:47 +02:00
parent 6f47ed0674
commit a77f74911d
64 changed files with 2864 additions and 1739 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Services\Rooms;
use App\Data\Rooms\RoomPageData;
use App\Models\Player;
use App\Models\Room;
use App\Models\User;
class RoomPageService
{
public function __construct(
private readonly RoomStatisticsService $statistics,
) {}
public function prepare(Room $room, Player $currentPlayer, ?User $user): RoomPageData
{
$isFavorite = $user !== null
&& $user->favoriteRooms()->whereKey($room->id)->exists();
$room->load([
'players' => fn ($query) => $query
->active()
->select(['id', 'room_id', 'user_id', 'name', 'is_moderator', 'created_at'])
->orderByDesc('is_moderator')
->orderBy('created_at'),
'players.votes' => fn ($query) => $query
->where('room_id', $room->id)
->where('round', $room->current_round),
]);
$currentVote = $room->players
->firstWhere('id', $currentPlayer->id)
?->votes
->first()
?->value;
return new RoomPageData(
room: $room,
currentPlayer: $currentPlayer,
isFavorite: $isFavorite,
currentVote: $currentVote,
statistics: $this->statistics->currentRound($room),
);
}
}