expose sets list endpoint
This commit is contained in:
parent
61ab8c09dc
commit
3d96a8d316
3 changed files with 49 additions and 0 deletions
26
backend/app/Http/Controllers/SetController.php
Normal file
26
backend/app/Http/Controllers/SetController.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Set\Set;
|
||||
use App\Set\UseCases\ListSets\ListSets;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SetController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ListSets $listSets,
|
||||
) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$sets = array_map(function (Set $set): array {
|
||||
return [
|
||||
'id' => $set->getId(),
|
||||
'name' => $set->getName(),
|
||||
];
|
||||
}, $this->listSets->execute());
|
||||
|
||||
return new JsonResponse(['sets' => $sets]);
|
||||
}
|
||||
}
|
||||
21
backend/app/Set/UseCases/ListSets/ListSets.php
Normal file
21
backend/app/Set/UseCases/ListSets/ListSets.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Set\UseCases\ListSets;
|
||||
|
||||
use App\Set\Set;
|
||||
use App\Set\SetRepository;
|
||||
|
||||
class ListSets
|
||||
{
|
||||
public function __construct(
|
||||
private SetRepository $setRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<Set>
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
return $this->setRepository->all();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue