Files
Mangarr/src/Domain/Manga/Application/QueryHandler/DownloadVolumeHandler.php
ext.jeremy.guillot@maxicoffee.domains c50f1638ee 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>
2026-03-09 17:54:35 +01:00

56 lines
1.8 KiB
PHP

<?php
namespace App\Domain\Manga\Application\QueryHandler;
use App\Domain\Manga\Application\Query\DownloadVolume;
use App\Domain\Manga\Application\Response\DownloadResponse;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Service\FileServiceInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Manga\Domain\Exception\VolumeNotFoundException;
use App\Domain\Shared\Domain\Contract\QueryHandlerInterface;
use App\Domain\Shared\Domain\Contract\QueryInterface;
use App\Domain\Shared\Domain\Contract\ResponseInterface;
readonly class DownloadVolumeHandler implements QueryHandlerInterface
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private FileServiceInterface $fileService
) {}
public function handle(QueryInterface $query): ResponseInterface
{
assert($query instanceof DownloadVolume);
$manga = $this->mangaRepository->findById($query->mangaId);
if (!$manga) {
throw new MangaNotFoundException($query->mangaId);
}
$chapters = $this->mangaRepository->findVisibleChaptersWithPagesByMangaIdAndVolume(
$query->mangaId,
$query->volume
);
if (empty($chapters)) {
throw new VolumeNotFoundException($query->mangaId, $query->volume);
}
$cbzPaths = [];
foreach ($chapters as $chapter) {
$cbzPaths[] = $chapter->getPagesDirectory();
}
$volumeName = sprintf('%s_vol%d',
$manga->getSlug()->getValue(),
$query->volume
);
$httpResponse = $this->fileService->createVolumeCbz($cbzPaths, $volumeName);
return new DownloadResponse($httpResponse);
}
}