chore: rattrapage
This commit is contained in:
parent
8e1c4637ba
commit
7fba3c6fcb
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = []
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user