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
@@ -179,7 +179,9 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
->setNumber($chapter->getNumber())
|
||||
->setTitle($chapter->getTitle())
|
||||
->setVolume($chapter->getVolume())
|
||||
->setVisible($chapter->isVisible());
|
||||
->setVisible($chapter->isVisible())
|
||||
->setPagesDirectory($chapter->getPagesDirectory())
|
||||
->setPageCount($chapter->getPageCount());
|
||||
|
||||
$this->entityManager->persist($entity);
|
||||
$this->entityManager->flush();
|
||||
@@ -187,6 +189,107 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
return new ChapterId((string) $entity->getId());
|
||||
}
|
||||
|
||||
public function findChapterById(string $id): ?Chapter
|
||||
{
|
||||
$entity = $this->entityManager->find(EntityChapter::class, $id);
|
||||
|
||||
return $entity ? $this->toChapterDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function findVisibleChapterById(string $id): ?Chapter
|
||||
{
|
||||
$entity = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(EntityChapter::class, 'c')
|
||||
->where('c.id = :id')
|
||||
->andWhere('c.visible = :visible')
|
||||
->setParameter('id', $id)
|
||||
->setParameter('visible', 1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
|
||||
return $entity ? $this->toChapterDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function findChapterByMangaIdAndNumber(string $mangaId, float $chapterNumber): ?Chapter
|
||||
{
|
||||
$entity = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(EntityChapter::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->andWhere('c.number = :chapterNumber')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setParameter('chapterNumber', $chapterNumber)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
|
||||
return $entity ? $this->toChapterDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function updateChapter(Chapter $chapter): void
|
||||
{
|
||||
$entity = $this->entityManager->find(EntityChapter::class, $chapter->getId());
|
||||
|
||||
if (!$entity) {
|
||||
throw new \RuntimeException(sprintf('Chapter with id %s not found', $chapter->getId()));
|
||||
}
|
||||
|
||||
$entity->setVisible($chapter->isVisible())
|
||||
->setPagesDirectory($chapter->getPagesDirectory())
|
||||
->setPageCount($chapter->getPageCount())
|
||||
->setTitle($chapter->getTitle())
|
||||
->setVolume($chapter->getVolume())
|
||||
// Keep cbzPath in sync during transition (Phase 4 will drop this column)
|
||||
->setCbzPath($chapter->getPagesDirectory());
|
||||
|
||||
$this->entityManager->persist($entity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteChapter(Chapter $chapter): void
|
||||
{
|
||||
$entity = $this->entityManager->find(EntityChapter::class, $chapter->getId());
|
||||
|
||||
if ($entity) {
|
||||
$this->entityManager->remove($entity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function findChaptersByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$entities = $this->entityManager->getRepository(EntityChapter::class)
|
||||
->findBy(['manga' => $mangaId, 'volume' => $volume]);
|
||||
|
||||
return array_map([$this, 'toChapterDomain'], $entities);
|
||||
}
|
||||
|
||||
public function findVisibleChaptersByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$entities = $this->entityManager->getRepository(EntityChapter::class)
|
||||
->findBy(['manga' => $mangaId, 'volume' => $volume, 'visible' => true]);
|
||||
|
||||
return array_map([$this, 'toChapterDomain'], $entities);
|
||||
}
|
||||
|
||||
public function findVisibleChaptersWithPagesByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$entities = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(EntityChapter::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->andWhere('c.volume = :volume')
|
||||
->andWhere('c.visible = true')
|
||||
->andWhere('c.pagesDirectory IS NOT NULL OR c.cbzPath IS NOT NULL')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setParameter('volume', $volume)
|
||||
->orderBy('c.number', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
return array_map([$this, 'toChapterDomain'], $entities);
|
||||
}
|
||||
|
||||
public function search(string $query, int $page = 1, int $limit = 20): array
|
||||
{
|
||||
$offset = ($page - 1) * $limit;
|
||||
@@ -314,12 +417,14 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
{
|
||||
return new Chapter(
|
||||
id: new ChapterId((string) $entity->getId()),
|
||||
mangaId: $entity->getManga()->getId(),
|
||||
mangaId: (string) $entity->getManga()->getId(),
|
||||
number: $entity->getNumber(),
|
||||
title: $entity->getTitle(),
|
||||
volume: $entity->getVolume(),
|
||||
isVisible: $entity->isVisible(),
|
||||
cbzPath: $entity->getCbzPath()
|
||||
// Fallback to cbzPath during transition (Phase 4 will drop cbzPath column)
|
||||
pagesDirectory: $entity->getPagesDirectory() ?? $entity->getCbzPath(),
|
||||
pageCount: $entity->getPageCount(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user