feat: Ajout d'un endpoint getBySlug
This commit is contained in:
parent
504c62c155
commit
30d26f530d
@@ -0,0 +1,26 @@
|
||||
<?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\GetMangaBySlugStateProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'Manga',
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/mangas/by-slug/{slug}',
|
||||
provider: GetMangaBySlugStateProvider::class,
|
||||
output: MangaDetail::class,
|
||||
name: 'get_manga_by_slug'
|
||||
)
|
||||
]
|
||||
)]
|
||||
class GetMangaBySlugResource
|
||||
{
|
||||
public function __construct(
|
||||
public string $slug
|
||||
) {}
|
||||
}
|
||||
@@ -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\GetMangaBySlug;
|
||||
use App\Domain\Manga\Application\QueryHandler\GetMangaBySlugHandler;
|
||||
use App\Domain\Manga\Infrastructure\ApiPlatform\Dto\MangaDetail;
|
||||
|
||||
readonly class GetMangaBySlugStateProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private GetMangaBySlugHandler $handler
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): MangaDetail
|
||||
{
|
||||
$query = new GetMangaBySlug($uriVariables['slug']);
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,14 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
|
||||
return $entity ? $this->toDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function findBySlug(MangaSlug $slug): ?DomainManga
|
||||
{
|
||||
$entity = $this->entityManager->getRepository(EntityManga::class)
|
||||
->findOneBy(['slug' => $slug->getValue()]);
|
||||
|
||||
return $entity ? $this->toDomain($entity) : null;
|
||||
}
|
||||
|
||||
public function save(DomainManga $manga): void
|
||||
{
|
||||
$entity = new EntityManga();
|
||||
|
||||
Reference in New Issue
Block a user