Merge branch 'main' of ssh://git.homelab.nestor-server.fr:2222/colgora/Mangarr
All checks were successful
Build and Deploy / deploy (push) Successful in 1m46s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m46s
# Conflicts: # src/Domain/Manga/Application/CommandHandler/DeleteChapterHandler.php # src/Domain/Manga/Application/CommandHandler/EditMultipleChaptersHandler.php # src/Domain/Manga/Application/EventListener/ChapterImportedEventListener.php # src/Domain/Manga/Application/EventListener/VolumeImportedEventListener.php # src/Domain/Manga/Application/Response/ChapterResponse.php # src/Domain/Manga/Infrastructure/ApiPlatform/State/Provider/DeleteCbzProvider.php # src/Domain/Manga/Infrastructure/ApiPlatform/State/Provider/DeleteChapterProvider.php # src/Domain/Manga/Infrastructure/Persistence/Repository/LegacyChapterRepository.php
This commit is contained in:
@@ -116,6 +116,44 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
if ($entity->getId()) {
|
||||
$manga->updateId(new MangaId((string) $entity->getId()));
|
||||
}
|
||||
|
||||
// Handle new chapters added through the aggregate
|
||||
foreach ($manga->pullNewChapters() as $chapter) {
|
||||
$mangaEntity = $this->entityManager->find(EntityManga::class, (int) $manga->getId()->getValue());
|
||||
$chapterEntity = new EntityChapter();
|
||||
$chapterEntity->setManga($mangaEntity)
|
||||
->setNumber($chapter->getNumber())
|
||||
->setTitle($chapter->getTitle())
|
||||
->setVolume($chapter->getVolume())
|
||||
->setVisible($chapter->isVisible())
|
||||
->setPagesDirectory($chapter->getPagesDirectory())
|
||||
->setPageCount($chapter->getPageCount());
|
||||
$this->entityManager->persist($chapterEntity);
|
||||
}
|
||||
|
||||
// Handle chapters modified through the aggregate
|
||||
foreach ($manga->pullModifiedChapters() as $chapter) {
|
||||
$chapterEntity = $this->entityManager->find(EntityChapter::class, $chapter->getId());
|
||||
if ($chapterEntity) {
|
||||
$chapterEntity->setVisible($chapter->isVisible())
|
||||
->setPagesDirectory($chapter->getPagesDirectory())
|
||||
->setPageCount($chapter->getPageCount())
|
||||
->setTitle($chapter->getTitle())
|
||||
->setVolume($chapter->getVolume())
|
||||
->setCbzPath($chapter->getPagesDirectory());
|
||||
$this->entityManager->persist($chapterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle chapters deleted through the aggregate
|
||||
foreach ($manga->pullChaptersToDelete() as $chapter) {
|
||||
$chapterEntity = $this->entityManager->find(EntityChapter::class, $chapter->getId());
|
||||
if ($chapterEntity) {
|
||||
$this->entityManager->remove($chapterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function delete(DomainManga $manga): void
|
||||
@@ -167,25 +205,75 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
return $entity ? $this->toDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function saveChapter(Chapter $chapter): ChapterId
|
||||
public function findChapterById(string $id): ?Chapter
|
||||
{
|
||||
$manga = $this->entityManager->find(EntityManga::class, $chapter->getMangaId());
|
||||
$entity = $this->entityManager->find(EntityChapter::class, $id);
|
||||
|
||||
if (!$manga) {
|
||||
throw new \RuntimeException('Manga not found');
|
||||
}
|
||||
return $entity ? $this->toChapterDomain($entity) : null;
|
||||
}
|
||||
|
||||
$entity = new EntityChapter();
|
||||
$entity->setManga($manga)
|
||||
->setNumber($chapter->getNumber())
|
||||
->setTitle($chapter->getTitle())
|
||||
->setVolume($chapter->getVolume())
|
||||
->setVisible($chapter->isVisible());
|
||||
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();
|
||||
|
||||
$this->entityManager->persist($entity);
|
||||
$this->entityManager->flush();
|
||||
return $entity ? $this->toChapterDomain($entity) : null;
|
||||
}
|
||||
|
||||
return new ChapterId((string) $entity->getId());
|
||||
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 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
|
||||
@@ -315,12 +403,14 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
{
|
||||
return new Chapter(
|
||||
id: new ChapterId((string) $entity->getId()),
|
||||
mangaId: $entity->getManga()->getId(),
|
||||
mangaId: new 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