refactor(manga): merge ChapterRepositoryInterface into MangaRepositoryInterface + pagesDirectory
- Supprime ChapterRepositoryInterface du domaine Manga (et ses implémentations LegacyChapterRepository et InMemoryChapterRepository) - Déplace toutes les méthodes chapter vers MangaRepositoryInterface avec nommage explicite (findChapterById, findVisibleChapterById, updateChapter, deleteChapter, etc.) - Remplace cbzPath par pagesDirectory + pageCount dans le modèle Chapter (transition : toChapterDomain conserve un fallback cbzPath pour les données existantes, updateChapter synchronise les deux colonnes jusqu'à la Phase 4) - Ajoute la migration Doctrine (pages_directory, page_count sur la table chapter) - Met à jour tous les handlers, listeners, query handlers et state providers du domaine Manga pour injecter uniquement MangaRepositoryInterface - Adapte les tests unitaires et InMemoryMangaRepository avec les nouvelles méthodes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
dae215dd3d
commit
c50f1638ee
@@ -18,6 +18,9 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
/** @var array<string, array<Chapter>> */
|
||||
private array $chapters = [];
|
||||
|
||||
/** @var array<string, Chapter> */
|
||||
private array $chaptersById = [];
|
||||
|
||||
/** @var array<Chapter> */
|
||||
private array $savedChapters = [];
|
||||
|
||||
@@ -101,12 +104,106 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
return count($this->chapters[$mangaId] ?? []);
|
||||
}
|
||||
|
||||
public function findChapterById(string $id): ?Chapter
|
||||
{
|
||||
return $this->chaptersById[$id] ?? null;
|
||||
}
|
||||
|
||||
public function findVisibleChapterById(string $id): ?Chapter
|
||||
{
|
||||
$chapter = $this->chaptersById[$id] ?? null;
|
||||
if ($chapter && $chapter->isVisible()) {
|
||||
return $chapter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function findChapterByMangaIdAndNumber(string $mangaId, float $chapterNumber): ?Chapter
|
||||
{
|
||||
foreach ($this->chaptersById as $chapter) {
|
||||
if ($chapter->getMangaId() === $mangaId && $chapter->getNumber() === $chapterNumber) {
|
||||
return $chapter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function saveChapter(Chapter $chapter): ChapterId
|
||||
{
|
||||
$this->savedChapters[] = $chapter;
|
||||
if (!isset($this->chapters[$chapter->getMangaId()])) {
|
||||
$this->chapters[$chapter->getMangaId()] = [];
|
||||
}
|
||||
$this->chapters[$chapter->getMangaId()][] = $chapter;
|
||||
$this->chaptersById[$chapter->getId()] = $chapter;
|
||||
return new ChapterId($chapter->getId());
|
||||
}
|
||||
|
||||
public function updateChapter(Chapter $chapter): void
|
||||
{
|
||||
$this->chaptersById[$chapter->getId()] = $chapter;
|
||||
|
||||
if (isset($this->chapters[$chapter->getMangaId()])) {
|
||||
foreach ($this->chapters[$chapter->getMangaId()] as $key => $existing) {
|
||||
if ($existing->getId() === $chapter->getId()) {
|
||||
$this->chapters[$chapter->getMangaId()][$key] = $chapter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteChapter(Chapter $chapter): void
|
||||
{
|
||||
unset($this->chaptersById[$chapter->getId()]);
|
||||
|
||||
if (isset($this->chapters[$chapter->getMangaId()])) {
|
||||
$this->chapters[$chapter->getMangaId()] = array_values(
|
||||
array_filter(
|
||||
$this->chapters[$chapter->getMangaId()],
|
||||
fn (Chapter $c) => $c->getId() !== $chapter->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function findChaptersByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->chaptersById,
|
||||
fn (Chapter $chapter) => $chapter->getMangaId() === $mangaId && $chapter->getVolume() === $volume
|
||||
));
|
||||
}
|
||||
|
||||
public function findVisibleChaptersByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->chaptersById,
|
||||
fn (Chapter $chapter) =>
|
||||
$chapter->getMangaId() === $mangaId &&
|
||||
$chapter->getVolume() === $volume &&
|
||||
$chapter->isVisible()
|
||||
));
|
||||
}
|
||||
|
||||
public function findVisibleChaptersWithPagesByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->chaptersById,
|
||||
fn (Chapter $chapter) =>
|
||||
$chapter->getMangaId() === $mangaId &&
|
||||
$chapter->getVolume() === $volume &&
|
||||
$chapter->isVisible() &&
|
||||
$chapter->isAvailable()
|
||||
));
|
||||
}
|
||||
|
||||
public function addChaptersToManga(string $mangaId, int $count): void
|
||||
{
|
||||
$this->chapters[$mangaId] = [];
|
||||
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$this->chapters[$mangaId][] = new Chapter(
|
||||
$chapter = new Chapter(
|
||||
id: new ChapterId((string)$i),
|
||||
mangaId: $mangaId,
|
||||
number: (float)$i,
|
||||
@@ -115,6 +212,8 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
isVisible: true,
|
||||
createdAt: new \DateTimeImmutable()
|
||||
);
|
||||
$this->chapters[$mangaId][] = $chapter;
|
||||
$this->chaptersById[$chapter->getId()] = $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,16 +227,6 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
public function saveChapter(Chapter $chapter): ChapterId
|
||||
{
|
||||
$this->savedChapters[] = $chapter;
|
||||
if (!isset($this->chapters[$chapter->getMangaId()])) {
|
||||
$this->chapters[$chapter->getMangaId()] = [];
|
||||
}
|
||||
$this->chapters[$chapter->getMangaId()][] = $chapter;
|
||||
return new ChapterId($chapter->getId());
|
||||
}
|
||||
|
||||
/** @return array<Chapter> */
|
||||
public function getSavedChapters(): array
|
||||
{
|
||||
@@ -148,6 +237,7 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
{
|
||||
$this->mangas = [];
|
||||
$this->chapters = [];
|
||||
$this->chaptersById = [];
|
||||
$this->savedChapters = [];
|
||||
}
|
||||
|
||||
@@ -161,7 +251,6 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
$manga->getDescription()
|
||||
];
|
||||
|
||||
// Ajouter les slugs alternatifs aux champs de recherche
|
||||
foreach ($manga->getAlternativeSlugs() as $altSlug) {
|
||||
$searchableFields[] = $altSlug;
|
||||
}
|
||||
@@ -186,6 +275,7 @@ 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])) {
|
||||
@@ -203,12 +293,10 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
|
||||
return array_filter(
|
||||
array_values($this->mangas),
|
||||
function (Manga $manga) use ($criteria) {
|
||||
// Vérifier si le monitoring est activé selon le critère
|
||||
if ($manga->getMonitoringStatus()->isEnabled() !== $criteria->enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérifier la date de dernière vérification si spécifiée
|
||||
if ($criteria->lastCheckBefore !== null) {
|
||||
$lastCheck = $manga->getLastMonitoringCheck();
|
||||
if ($lastCheck === null || $lastCheck >= $criteria->lastCheckBefore) {
|
||||
|
||||
Reference in New Issue
Block a user