mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 20:12:10 +00:00
fix: refactored the codebase
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user