feat: SearchManga endpoint + tests
This commit is contained in:
parent
6667cc224b
commit
ae0eac3197
10
src/Domain/Manga/Application/Query/SearchManga.php
Normal file
10
src/Domain/Manga/Application/Query/SearchManga.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Query;
|
||||
|
||||
readonly class SearchManga
|
||||
{
|
||||
public function __construct(
|
||||
public string $title
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\QueryHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Query\SearchManga;
|
||||
use App\Domain\Manga\Application\Response\MangaSearchItem;
|
||||
use App\Domain\Manga\Application\Response\MangaSearchResponse;
|
||||
use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface;
|
||||
|
||||
readonly class SearchMangaHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MangaProviderInterface $mangaProvider
|
||||
) {}
|
||||
|
||||
public function handle(SearchManga $query): MangaSearchResponse
|
||||
{
|
||||
$mangaCollection = $this->mangaProvider->search($query->title);
|
||||
|
||||
return new MangaSearchResponse(
|
||||
array_map(
|
||||
fn ($manga) => new MangaSearchItem(
|
||||
externalId: $manga->getExternalId()->getValue(),
|
||||
title: $manga->getTitle()->getValue(),
|
||||
slug: $manga->getSlug()->getValue(),
|
||||
description: $manga->getDescription(),
|
||||
author: $manga->getAuthor(),
|
||||
publicationYear: $manga->getPublicationYear(),
|
||||
genres: $manga->getGenres(),
|
||||
status: $manga->getStatus(),
|
||||
imageUrl: $manga->getImageUrl(),
|
||||
rating: $manga->getRating()
|
||||
),
|
||||
$mangaCollection->getItems()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
19
src/Domain/Manga/Application/Response/MangaSearchItem.php
Normal file
19
src/Domain/Manga/Application/Response/MangaSearchItem.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Response;
|
||||
|
||||
readonly class MangaSearchItem
|
||||
{
|
||||
public function __construct(
|
||||
public string $externalId,
|
||||
public string $title,
|
||||
public string $slug,
|
||||
public string $description,
|
||||
public string $author,
|
||||
public int $publicationYear,
|
||||
public array $genres,
|
||||
public string $status,
|
||||
public ?string $imageUrl,
|
||||
public ?float $rating
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Manga\Application\Response;
|
||||
|
||||
readonly class MangaSearchResponse
|
||||
{
|
||||
/** @var MangaSearchItem[] */
|
||||
public array $items;
|
||||
|
||||
/**
|
||||
* @param MangaSearchItem[] $items
|
||||
*/
|
||||
public function __construct(array $items)
|
||||
{
|
||||
$this->items = $items;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user