feat: GetManga endpoint + tests
This commit is contained in:
parent
e3d380eadd
commit
2f615a4936
10
src/Domain/Manga/Application/Query/GetManga.php
Normal file
10
src/Domain/Manga/Application/Query/GetManga.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Query;
|
||||
|
||||
readonly class GetManga
|
||||
{
|
||||
public function __construct(
|
||||
public string $id
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\QueryHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Query\GetManga;
|
||||
use App\Domain\Manga\Application\Response\MangaResponse;
|
||||
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
|
||||
readonly class GetMangaHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MangaRepositoryInterface $mangaRepository
|
||||
) {}
|
||||
|
||||
public function handle(GetManga $query): MangaResponse
|
||||
{
|
||||
$manga = $this->mangaRepository->findById($query->id);
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
20
src/Domain/Manga/Application/Response/MangaResponse.php
Normal file
20
src/Domain/Manga/Application/Response/MangaResponse.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Response;
|
||||
|
||||
readonly class MangaResponse
|
||||
{
|
||||
public function __construct(
|
||||
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
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user