add sets endpoint
This commit is contained in:
parent
a74bb853d4
commit
c4b95137e5
2 changed files with 37 additions and 0 deletions
35
backend/app/Controllers/SetController.php
Normal file
35
backend/app/Controllers/SetController.php
Normal 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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Controllers\AuthController;
|
||||
use App\Controllers\SetController;
|
||||
use App\Http\Middleware\AuthMiddleware;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
|
@ -8,3 +9,4 @@ Route::post('/login', [AuthController::class, 'login']);
|
|||
Route::post('/logout', [AuthController::class, 'logout']);
|
||||
Route::get('/me', [AuthController::class, 'me'])
|
||||
->middleware(AuthMiddleware::class);
|
||||
Route::get('/sets', [SetController::class, 'index']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue