mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 19:52:09 +00:00
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Data\Rooms\RoomPageData;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class RoomResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
/** @var RoomPageData $pageData */
|
|
$pageData = $this->resource;
|
|
$room = $pageData->room;
|
|
|
|
return [
|
|
'id' => $room->id,
|
|
'title' => $room->title,
|
|
'join_code' => $room->join_code,
|
|
'owner_id' => $room->owner_id,
|
|
'is_favorite' => $pageData->isFavorite,
|
|
'current_round' => $room->current_round,
|
|
'revealed' => $room->revealed_at !== null,
|
|
'state_version' => $room->state_version,
|
|
'statistics' => $pageData->statistics,
|
|
'deck' => (new RoomDeckResource($room->deck_config))->resolve($request),
|
|
'players' => $room->players
|
|
->map(fn ($player) => (new RoomPlayerResource($player, $room))->resolve($request))
|
|
->all(),
|
|
];
|
|
}
|
|
}
|