feat: Image saving for manga creation
This commit is contained in:
parent
50080f9779
commit
4017cabff2
@@ -5,14 +5,17 @@ namespace App\Domain\Manga\Application\CommandHandler;
|
||||
use App\Domain\Manga\Application\Command\CreateMangaFromMangadex;
|
||||
use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Contract\Service\ImageProcessorInterface;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls;
|
||||
|
||||
readonly class CreateMangaFromMangadexHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MangaProviderInterface $mangaProvider,
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
private MangaRepositoryInterface $mangaRepository,
|
||||
private ImageProcessorInterface $imageProcessor
|
||||
) {}
|
||||
|
||||
public function handle(CreateMangaFromMangadex $command): void
|
||||
@@ -23,6 +26,19 @@ readonly class CreateMangaFromMangadexHandler
|
||||
throw new MangaNotFoundException('Manga not found on Mangadex');
|
||||
}
|
||||
|
||||
try {
|
||||
// Télécharge l'image originale
|
||||
$fullImagePath = $this->imageProcessor->downloadImage($manga->getImageUrl());
|
||||
|
||||
// Crée la miniature à partir de l'image originale
|
||||
$thumbnailPath = $this->imageProcessor->createThumbnail($fullImagePath);
|
||||
|
||||
// Met à jour le manga avec les nouveaux chemins d'images
|
||||
$manga->updateImageUrls(new ImageUrls($fullImagePath, $thumbnailPath));
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Erreur lors du traitement de l\'image : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->mangaRepository->save($manga);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user