51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Element\ElementRepository;
|
|
use App\Set\Set as DomainSet;
|
|
use App\Set\SetRepository;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class SetController
|
|
{
|
|
public function __construct(
|
|
private SetRepository $setRepository,
|
|
private ElementRepository $elementRepository,
|
|
) {
|
|
}
|
|
|
|
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,
|
|
* rootElementId: int|null
|
|
* }
|
|
*/
|
|
private function buildSetPayload(DomainSet $set): array
|
|
{
|
|
$rootElement = $this->elementRepository->findRootBySet($set);
|
|
|
|
return [
|
|
'id' => $set->getId(),
|
|
'name' => $set->getName(),
|
|
'description' => $set->getDescription(),
|
|
'iconImageUrl' => $set->getIconImageUrl(),
|
|
'rootElementId' => $rootElement?->getId(),
|
|
];
|
|
}
|
|
}
|