Rabbi_Gerzi/backend/app/Controllers/SetController.php

44 lines
949 B
PHP

<?php
namespace App\Controllers;
use App\Set\Set as DomainSet;
use App\Set\SetRepository;
use Illuminate\Http\JsonResponse;
class SetController
{
public function __construct(private SetRepository $setRepository)
{
}
public function index(): JsonResponse
{
$sets = [];
foreach ($this->setRepository->getAll() as $set) {
$sets[] = $this->buildSetPayload($set);
}
return new JsonResponse([
'sets' => $sets,
], 200);
}
/**
* @return array{
* id: int,
* name: string,
* description: string,
* iconImageUrl: string
* }
*/
private function buildSetPayload(DomainSet $set): array
{
return [
'id' => $set->getId(),
'name' => $set->getName(),
'description' => $set->getDescription(),
'iconImageUrl' => $set->getIconImageUrl(),
];
}
}