feat: ajout de la gestion des chapitres de manga, incluant la récupération et la sauvegarde des chapitres en français et en anglais, ainsi que l'optimisation de la logique de sauvegarde pour éviter les doublons

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-04-01 16:01:55 +02:00
parent 34dfa57dc0
commit 0111f1b5f1
12 changed files with 254 additions and 78 deletions

View File

@@ -13,7 +13,7 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
{
/** @var array<string, Manga> */
private array $mangas = [];
/** @var array<string, array<Chapter>> */
private array $chapters = [];
@@ -28,13 +28,13 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
$valueA = $this->getPropertyValue($a, $sortBy);
$valueB = $this->getPropertyValue($b, $sortBy);
return $sortOrder === 'asc'
? $valueA <=> $valueB
return $sortOrder === 'asc'
? $valueA <=> $valueB
: $valueB <=> $valueA;
});
$offset = ($page - 1) * $limit;
return array_slice($sortedMangas, $offset, $limit);
}
@@ -103,7 +103,7 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
public function addChaptersToManga(string $mangaId, int $count): void
{
$this->chapters[$mangaId] = [];
for ($i = 1; $i <= $count; $i++) {
$this->chapters[$mangaId][] = new Chapter(
id: new ChapterId((string)$i),
@@ -179,4 +179,15 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
{
return count($this->search($query, 1, PHP_INT_MAX));
}
public function findExistingChaptersByNumbers(string $mangaId, array $chapterNumbers): array
{
if (!isset($this->chapters[$mangaId])) {
return [];
}
return array_filter(
$this->chapters[$mangaId],
fn (Chapter $chapter) => in_array($chapter->getNumber(), $chapterNumbers)
);
}
}