35 lines
736 B
PHP
35 lines
736 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}
|
|
*/
|
|
private function buildSetPayload(DomainSet $set): array
|
|
{
|
|
return [
|
|
'id' => $set->getId(),
|
|
'name' => $set->getName(),
|
|
];
|
|
}
|
|
}
|