feat: GetMangaList endpoint + tests + test db

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-10 19:21:14 +01:00
parent 073439163b
commit e3d380eadd
34 changed files with 932 additions and 23 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Domain\Manga\Application\Query;
readonly class GetMangaList
{
public function __construct(
public ?int $page = 1,
public ?int $limit = 20,
public ?string $sortBy = 'title',
public ?string $sortOrder = 'asc'
) {}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Domain\Manga\Application\QueryHandler;
use App\Domain\Manga\Application\Query\GetMangaList;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Application\Response\MangaListResponse;
readonly class GetMangaListHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository
) {}
public function handle(GetMangaList $query): MangaListResponse
{
$mangas = $this->mangaRepository->findAll(
page: $query->page,
limit: $query->limit,
sortBy: $query->sortBy,
sortOrder: $query->sortOrder
);
$total = $this->mangaRepository->count();
return new MangaListResponse(
mangas: $mangas,
total: $total,
page: $query->page,
limit: $query->limit
);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Domain\Manga\Application\Response;
readonly class MangaListResponse
{
public function __construct(
public array $mangas,
public int $total,
public int $page,
public int $limit
) {}
public function getTotalPages(): int
{
return (int) ceil($this->total / $this->limit);
}
public function hasNextPage(): bool
{
return $this->page < $this->getTotalPages();
}
public function hasPreviousPage(): bool
{
return $this->page > 1;
}
}