feat: endpoint pour la création d'un manga directement via l'api

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-11 15:59:53 +01:00
parent 4017cabff2
commit 3dc0a0b406
9 changed files with 409 additions and 8 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\CreateManga;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Contract\Service\ImageProcessorInterface;
use App\Domain\Manga\Domain\Model\Manga;
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
use App\Domain\Manga\Domain\Model\ValueObject\ImageUrls;
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
use Ramsey\Uuid\Uuid;
readonly class CreateMangaHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private ImageProcessorInterface $imageProcessor
) {}
public function handle(CreateManga $command): void
{
$manga = new Manga(
new MangaId(Uuid::uuid4()->toString()),
new MangaTitle($command->title),
new MangaSlug($command->slug),
$command->description,
$command->author,
$command->publicationYear,
$command->genres,
$command->status,
$command->externalId ? new ExternalId($command->externalId) : null,
$command->imageUrl,
$command->rating
);
if (!is_null($command->imageUrl)) {
try {
$fullImagePath = $this->imageProcessor->downloadImage($command->imageUrl);
$thumbnailPath = $this->imageProcessor->createThumbnail($fullImagePath);
$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);
}
}