mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 15:32:09 +00:00
fix: refactored the codebase
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Rooms;
|
||||
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class DashboardRoomService
|
||||
{
|
||||
/**
|
||||
* @return array{owned: Collection<int, Room>, favorites: Collection<int, Room>}
|
||||
*/
|
||||
public function forUser(User $user): array
|
||||
{
|
||||
$ownedRooms = $user
|
||||
->ownedRooms()
|
||||
->withCount('players')
|
||||
->withCount(['activePlayers as active_player_count'])
|
||||
->orderByRaw('closed_at IS NOT NULL')
|
||||
->orderByDesc('last_activity_at')
|
||||
->get();
|
||||
|
||||
$favoriteRooms = $user
|
||||
->favoriteRooms()
|
||||
->withCount('players')
|
||||
->withCount(['activePlayers as active_player_count'])
|
||||
->orderByRaw('closed_at IS NOT NULL')
|
||||
->orderByDesc('last_activity_at')
|
||||
->get();
|
||||
|
||||
return [
|
||||
'owned' => $ownedRooms,
|
||||
'favorites' => $favoriteRooms,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user