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
@@ -4,7 +4,7 @@ namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
|
||||
use App\Domain\Manga\Domain\Exception\CbzFileNotFoundException;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Resource\DeleteCbzResource;
|
||||
@@ -13,7 +13,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
readonly class DeleteCbzProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepositoryInterface $chapterRepository
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): DeleteCbzResource
|
||||
@@ -25,7 +25,7 @@ readonly class DeleteCbzProvider implements ProviderInterface
|
||||
$chapterId = $uriVariables['id'];
|
||||
|
||||
try {
|
||||
$chapter = $this->chapterRepository->findVisibleById($chapterId);
|
||||
$chapter = $this->mangaRepository->findVisibleChapterById($chapterId);
|
||||
|
||||
if (!$chapter) {
|
||||
throw new ChapterNotFoundException($chapterId);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\ChapterNotFoundException;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Resource\DeleteChapterResource;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
@@ -12,7 +12,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
readonly class DeleteChapterProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepositoryInterface $chapterRepository
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): DeleteChapterResource
|
||||
@@ -24,7 +24,7 @@ readonly class DeleteChapterProvider implements ProviderInterface
|
||||
$chapterId = $uriVariables['id'];
|
||||
|
||||
try {
|
||||
$chapter = $this->chapterRepository->findVisibleById($chapterId);
|
||||
$chapter = $this->mangaRepository->findVisibleChapterById($chapterId);
|
||||
|
||||
if (!$chapter) {
|
||||
throw new ChapterNotFoundException($chapterId);
|
||||
|
||||
@@ -52,7 +52,7 @@ readonly class GetMangaChaptersStateProvider implements ProviderInterface
|
||||
title: $chapter->title,
|
||||
volume: $chapter->volume,
|
||||
isVisible: $chapter->isVisible,
|
||||
isAvailable: $chapter->cbzPath !== null,
|
||||
isAvailable: $chapter->pagesDirectory !== null,
|
||||
createdAt: $chapter->createdAt->format(\DateTimeInterface::RFC3339)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\Persistence\Repository;
|
||||
|
||||
use App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Model\Chapter;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
|
||||
use App\Entity\Chapter as ChapterEntity;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
readonly class LegacyChapterRepository implements ChapterRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager
|
||||
) {}
|
||||
|
||||
public function findById(string $id): ?Chapter
|
||||
{
|
||||
$entity = $this->entityManager->find(ChapterEntity::class, $id);
|
||||
|
||||
return $entity ? $this->toDomainModel($entity) : null;
|
||||
}
|
||||
|
||||
public function findVisibleById(string $id): ?Chapter
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(ChapterEntity::class, 'c')
|
||||
->where('c.id = :id')
|
||||
->andWhere('c.visible = :visible')
|
||||
->setParameter('id', $id)
|
||||
->setParameter('visible', 1);
|
||||
|
||||
$entity = $qb->getQuery()->getOneOrNullResult();
|
||||
|
||||
return $entity ? $this->toDomainModel($entity) : null;
|
||||
}
|
||||
|
||||
public function findByMangaIdAndChapterNumber(string $mangaId, float $chapterNumber): ?Chapter
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(ChapterEntity::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->andWhere('c.number = :chapterNumber')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setParameter('chapterNumber', $chapterNumber);
|
||||
|
||||
$entity = $qb->getQuery()->getOneOrNullResult();
|
||||
|
||||
return $entity ? $this->toDomainModel($entity) : null;
|
||||
}
|
||||
|
||||
public function save(Chapter $chapter): void
|
||||
{
|
||||
$entity = $this->entityManager->find(ChapterEntity::class, $chapter->getId());
|
||||
|
||||
if (!$entity) {
|
||||
throw new \RuntimeException(sprintf('Chapter with id %s not found', $chapter->getId()));
|
||||
}
|
||||
|
||||
$entity->setVisible($chapter->isVisible());
|
||||
$entity->setCbzPath($chapter->getCbzPath());
|
||||
$entity->setTitle($chapter->getTitle());
|
||||
$entity->setVolume($chapter->getVolume());
|
||||
|
||||
$this->entityManager->persist($entity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function delete(Chapter $chapter): void
|
||||
{
|
||||
$entity = $this->entityManager->find(ChapterEntity::class, $chapter->getId());
|
||||
|
||||
if ($entity) {
|
||||
$this->entityManager->remove($entity);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function findByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$entities = $this->entityManager->getRepository(ChapterEntity::class)
|
||||
->findBy(['manga' => $mangaId, 'volume' => $volume]);
|
||||
|
||||
return array_map([$this, 'toDomainModel'], $entities);
|
||||
}
|
||||
|
||||
public function findVisibleByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$entities = $this->entityManager->getRepository(ChapterEntity::class)
|
||||
->findBy(['manga' => $mangaId, 'volume' => $volume, 'visible' => true]);
|
||||
|
||||
return array_map([$this, 'toDomainModel'], $entities);
|
||||
}
|
||||
|
||||
public function findVisibleWithCbzByMangaIdAndVolume(string $mangaId, int $volume): array
|
||||
{
|
||||
$qb = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from(ChapterEntity::class, 'c')
|
||||
->where('c.manga = :mangaId')
|
||||
->andWhere('c.volume = :volume')
|
||||
->andWhere('c.visible = true')
|
||||
->andWhere('c.cbzPath IS NOT NULL')
|
||||
->setParameter('mangaId', $mangaId)
|
||||
->setParameter('volume', $volume)
|
||||
->orderBy('c.number', 'ASC');
|
||||
|
||||
$entities = $qb->getQuery()->getResult();
|
||||
|
||||
return array_map([$this, 'toDomainModel'], $entities);
|
||||
}
|
||||
|
||||
private function toDomainModel(ChapterEntity $entity): Chapter
|
||||
{
|
||||
return new Chapter(
|
||||
new ChapterId((string) $entity->getId()),
|
||||
(string) $entity->getManga()->getId(),
|
||||
$entity->getNumber(),
|
||||
$entity->getTitle(),
|
||||
$entity->getVolume(),
|
||||
$entity->isVisible(),
|
||||
$entity->getCbzPath(),
|
||||
new \DateTimeImmutable()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
isset($chapterData['attributes']['volume']) ? (int) $chapterData['attributes']['volume'] : null,
|
||||
true,
|
||||
null,
|
||||
0,
|
||||
new \DateTimeImmutable()
|
||||
);
|
||||
$chapterLanguages[(string) $chapterNumber] = $language;
|
||||
@@ -142,7 +143,8 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
$currentChapter->getTitle(),
|
||||
null, // volume = null
|
||||
$currentChapter->isVisible(),
|
||||
$currentChapter->getCbzPath(),
|
||||
$currentChapter->getPagesDirectory(),
|
||||
$currentChapter->getPageCount(),
|
||||
$currentChapter->getCreatedAt()
|
||||
);
|
||||
}
|
||||
@@ -155,7 +157,8 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
$currentChapter->getTitle(),
|
||||
$prevVolume, // prend le volume des adjacents
|
||||
$currentChapter->isVisible(),
|
||||
$currentChapter->getCbzPath(),
|
||||
$currentChapter->getPagesDirectory(),
|
||||
$currentChapter->getPageCount(),
|
||||
$currentChapter->getCreatedAt()
|
||||
);
|
||||
}
|
||||
@@ -209,7 +212,8 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
$currentChapter->getTitle(),
|
||||
$prevVolume,
|
||||
$currentChapter->isVisible(),
|
||||
$currentChapter->getCbzPath(),
|
||||
$currentChapter->getPagesDirectory(),
|
||||
$currentChapter->getPageCount(),
|
||||
$currentChapter->getCreatedAt()
|
||||
);
|
||||
}
|
||||
@@ -222,7 +226,8 @@ readonly class MangadxChapterSynchronizationService implements ChapterSynchroniz
|
||||
$currentChapter->getTitle(),
|
||||
$nextVolume,
|
||||
$currentChapter->isVisible(),
|
||||
$currentChapter->getCbzPath(),
|
||||
$currentChapter->getPagesDirectory(),
|
||||
$currentChapter->getPageCount(),
|
||||
$currentChapter->getCreatedAt()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user