feat: ajout d'une route GetMangaByIdHandler.php et fix de la SearchBar.vue

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-25 22:44:26 +01:00
parent ed0a075a6c
commit d9e935f7de
26 changed files with 519 additions and 79 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Domain\Manga\Application\Query;
readonly class SearchLocalManga
{
public function __construct(
public string $query,
public int $page = 1,
public int $limit = 20
) {
}
}

View File

@@ -32,6 +32,7 @@ readonly class GetMangaByIdHandler
status: $manga->getStatus(),
externalId: $manga->getExternalId()?->getValue(),
imageUrl: $manga->getImageUrl(),
thumbnailUrl: $manga->getImageUrls()->getThumbnail(),
rating: $manga->getRating()
);
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Domain\Manga\Application\QueryHandler;
use App\Domain\Manga\Application\Query\SearchLocalManga;
use App\Domain\Manga\Application\Response\MangaListResponse;
use App\Domain\Manga\Application\Response\MangaResponse;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Model\Manga;
readonly class SearchLocalMangaHandler
{
public function __construct(
private MangaRepositoryInterface $repository
) {}
public function handle(SearchLocalManga $query): MangaListResponse
{
$mangas = $this->repository->search($query->query, $query->page, $query->limit);
$total = $this->repository->countSearch($query->query);
return new MangaListResponse(
mangas: array_map(
fn (Manga $manga) => 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->getImageUrls()->getFull(),
thumbnailUrl: $manga->getImageUrls()->getThumbnail(),
rating: $manga->getRating()
),
$mangas
),
total: $total,
page: $query->page,
limit: $query->limit
);
}
}

View File

@@ -15,6 +15,7 @@ readonly class MangaResponse
public string $status,
public ?string $externalId,
public ?string $imageUrl,
public ?string $thumbnailUrl,
public ?float $rating
) {}
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Domain\Manga\Application\Response;
readonly class MangaSearchItem
{
public function __construct(
public int $id,
public string $externalId,
public string $title,
public string $slug,
@@ -14,6 +15,7 @@ readonly class MangaSearchItem
public array $genres,
public string $status,
public ?string $imageUrl,
public ?string $thumbnailUrl,
public ?float $rating
) {}
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Domain\Manga\Application\Response;
readonly class SearchLocalMangaResponse
{
/**
* @param MangaSearchItem[] $items
*/
public function __construct(
public array $items,
public int $total,
public int $page,
public int $limit
) {}
public function hasNextPage(): bool
{
return $this->total > ($this->page * $this->limit);
}
public function hasPreviousPage(): bool
{
return $this->page > 1;
}
}