add sets endpoint

This commit is contained in:
Yisroel Baum 2026-05-25 19:59:40 +03:00
parent a74bb853d4
commit c4b95137e5
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,35 @@
<?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}
*/
private function buildSetPayload(DomainSet $set): array
{
return [
'id' => $set->getId(),
'name' => $set->getName(),
];
}
}