Files
Mangarr/src/Domain/Manga/Application/QueryHandler/GetMangaListHandler.php
ext.jeremy.guillot@maxicoffee.domains 7fba3c6fcb chore: rattrapage
2026-03-14 00:45:29 +01:00

45 lines
1.2 KiB
PHP

<?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();
$chapterCounts = [];
foreach ($mangas as $manga) {
$id = $manga->getId()->getValue();
$chapterCounts[$id] = [
'total' => $this->mangaRepository->countChapters($id),
'scraped' => $this->mangaRepository->countAvailableChapters($id),
];
}
return new MangaListResponse(
mangas: $mangas,
total: $total,
page: $query->page,
limit: $query->limit,
chapterCounts: $chapterCounts
);
}
}