feat: endpoint FetchMangaChapters et tests
This commit is contained in:
parent
3dc0a0b406
commit
879b8fa2dc
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor\FetchMangaChaptersProcessor;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'FetchMangaChapters',
|
||||
operations: [
|
||||
new Post(
|
||||
uriTemplate: '/manga/chapters/fetch',
|
||||
processor: FetchMangaChaptersProcessor::class,
|
||||
status: 202
|
||||
)
|
||||
]
|
||||
)]
|
||||
class FetchMangaChaptersResource
|
||||
{
|
||||
public function __construct(
|
||||
#[Assert\NotBlank]
|
||||
public string $externalId
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Domain\Manga\Application\Command\FetchMangaChapters;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Resource\FetchMangaChaptersResource;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
readonly class FetchMangaChaptersProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private MessageBusInterface $messageBus
|
||||
) {}
|
||||
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
|
||||
{
|
||||
if (!$data instanceof FetchMangaChaptersResource) {
|
||||
throw new \InvalidArgumentException('Invalid resource type');
|
||||
}
|
||||
|
||||
$this->messageBus->dispatch(
|
||||
new FetchMangaChapters($data->externalId)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user