chore: rattrapage

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-14 00:45:29 +01:00
parent 8e1c4637ba
commit 7fba3c6fcb
14 changed files with 87 additions and 23 deletions

View File

@@ -24,11 +24,21 @@ readonly class GetMangaListHandler
$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
limit: $query->limit,
chapterCounts: $chapterCounts
);
}
}

View File

@@ -8,7 +8,8 @@ readonly class MangaListResponse
public array $mangas,
public int $total,
public int $page,
public int $limit
public int $limit,
public array $chapterCounts = []
) {
}

View File

@@ -31,6 +31,7 @@ interface MangaRepositoryInterface
public function findChapters(string $mangaId, int $page = 1, int $limit = 20, string $sortOrder = 'desc'): array;
public function countChapters(string $mangaId): int;
public function countAvailableChapters(string $mangaId): int;
public function findChapterById(string $id): ?Chapter;
public function findVisibleChapterById(string $id): ?Chapter;
public function findChapterByMangaIdAndNumber(string $mangaId, float $chapterNumber): ?Chapter;

View File

@@ -21,6 +21,9 @@ readonly class MangaListItem
public string $status,
public ?float $rating,
public DateTimeImmutable $createdAt,
public bool $monitored = false,
public int $chaptersTotal = 0,
public int $chaptersScraped = 0,
) {
}
}

View File

@@ -29,7 +29,10 @@ readonly class GetMangaListStateProvider implements ProviderInterface
return new MangaCollection(
items: array_map(
fn (Manga $manga) => $this->createMangaListItem($manga),
fn (Manga $manga) => $this->createMangaListItem(
$manga,
$response->chapterCounts[$manga->getId()->getValue()] ?? []
),
$response->mangas
),
total: $response->total,
@@ -40,7 +43,7 @@ readonly class GetMangaListStateProvider implements ProviderInterface
);
}
private function createMangaListItem(Manga $manga): MangaListItem
private function createMangaListItem(Manga $manga, array $counts = []): MangaListItem
{
return new MangaListItem(
id: $manga->getId()->getValue(),
@@ -54,7 +57,10 @@ readonly class GetMangaListStateProvider implements ProviderInterface
genres: $manga->getGenres(),
status: $manga->getStatus(),
rating: $manga->getRating(),
createdAt: $manga->getCreatedAt()
createdAt: $manga->getCreatedAt(),
monitored: $manga->getMonitoringStatus()->isEnabled(),
chaptersTotal: $counts['total'] ?? 0,
chaptersScraped: $counts['scraped'] ?? 0,
);
}
}

View File

@@ -196,6 +196,18 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
->getSingleScalarResult();
}
public function countAvailableChapters(string $mangaId): int
{
return $this->entityManager->createQueryBuilder()
->select('COUNT(c.id)')
->from(EntityChapter::class, 'c')
->where('c.manga = :mangaId')
->andWhere('c.pagesDirectory IS NOT NULL OR c.cbzPath IS NOT NULL')
->setParameter('mangaId', $mangaId)
->getQuery()
->getSingleScalarResult();
}
public function findByExternalId(ExternalId $externalId): ?DomainManga
{
$entity = $this->entityManager->getRepository(EntityManga::class)->findOneBy([