feat: CreateMangaFromMangadex endpoint + tests, missing image saving

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-02-11 00:10:54 +01:00
parent ae0eac3197
commit 50080f9779
14 changed files with 387 additions and 29 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\CreateMangaProcessor;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
shortName: 'CreateManga',
operations: [
new Post(
uriTemplate: '/mangas/create-from-mangadex',
processor: CreateMangaProcessor::class,
openapiContext: [
'summary' => 'Create a new manga from Mangadex',
'description' => 'Creates a new manga by fetching its data from Mangadex using an external ID'
]
)
]
)]
class CreateMangaResource
{
#[Assert\NotBlank]
public string $externalId;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Domain\Manga\Application\Command\CreateMangaFromMangadex;
use App\Domain\Manga\Application\CommandHandler\CreateMangaFromMangadexHandler;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
readonly class CreateMangaProcessor implements ProcessorInterface
{
public function __construct(
private CreateMangaFromMangadexHandler $handler
) {}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
try {
$this->handler->handle(new CreateMangaFromMangadex($data->externalId));
} catch (MangaNotFoundException $e) {
throw new NotFoundHttpException($e->getMessage());
}
}
}