feat: GetManga endpoint + tests
This commit is contained in:
parent
e3d380eadd
commit
2f615a4936
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Dto;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
|
||||
readonly class MangaDetail
|
||||
{
|
||||
public function __construct(
|
||||
#[ApiProperty(identifier: true)]
|
||||
public string $id,
|
||||
public string $title,
|
||||
public string $slug,
|
||||
public string $description,
|
||||
public string $author,
|
||||
public int $publicationYear,
|
||||
public array $genres,
|
||||
public string $status,
|
||||
public ?string $externalId,
|
||||
public ?string $imageUrl,
|
||||
public ?float $rating
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\ApiPlatform\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaDetail;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider\GetMangaStateProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'Manga',
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/mangas/{id}',
|
||||
provider: GetMangaStateProvider::class,
|
||||
output: MangaDetail::class
|
||||
)
|
||||
]
|
||||
)]
|
||||
class MangaResource
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Infrastructure\ApiPlatform\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Domain\Manga\Application\Query\GetManga;
|
||||
use App\Domain\Manga\Application\QueryHandler\GetMangaHandler;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaDetail;
|
||||
|
||||
readonly class GetMangaStateProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private GetMangaHandler $handler
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): MangaDetail
|
||||
{
|
||||
$query = new GetManga($uriVariables['id']);
|
||||
$response = $this->handler->handle($query);
|
||||
|
||||
return new MangaDetail(
|
||||
id: $response->id,
|
||||
title: $response->title,
|
||||
slug: $response->slug,
|
||||
description: $response->description,
|
||||
author: $response->author,
|
||||
publicationYear: $response->publicationYear,
|
||||
genres: $response->genres,
|
||||
status: $response->status,
|
||||
externalId: $response->externalId,
|
||||
imageUrl: $response->imageUrl,
|
||||
rating: $response->rating
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user