feat: Ajout d'un endpoint getBySlug
This commit is contained in:
parent
504c62c155
commit
30d26f530d
10
src/Domain/Manga/Application/Query/GetMangaBySlug.php
Normal file
10
src/Domain/Manga/Application/Query/GetMangaBySlug.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Query;
|
||||
|
||||
readonly class GetMangaBySlug
|
||||
{
|
||||
public function __construct(
|
||||
public string $slug
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\QueryHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Query\GetMangaBySlug;
|
||||
use App\Domain\Manga\Application\Response\MangaResponse;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
|
||||
|
||||
readonly class GetMangaBySlugHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
) {}
|
||||
|
||||
public function handle(GetMangaBySlug $query): MangaResponse
|
||||
{
|
||||
$manga = $this->mangaRepository->findBySlug(new MangaSlug($query->slug));
|
||||
|
||||
if (!$manga) {
|
||||
throw new MangaNotFoundException();
|
||||
}
|
||||
|
||||
return new MangaResponse(
|
||||
id: $manga->getId()->getValue(),
|
||||
title: $manga->getTitle()->getValue(),
|
||||
slug: $manga->getSlug()->getValue(),
|
||||
description: $manga->getDescription(),
|
||||
author: $manga->getAuthor(),
|
||||
publicationYear: $manga->getPublicationYear(),
|
||||
genres: $manga->getGenres(),
|
||||
status: $manga->getStatus(),
|
||||
externalId: $manga->getExternalId()?->getValue(),
|
||||
imageUrl: $manga->getImageUrl(),
|
||||
rating: $manga->getRating()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user