mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- AppServiceProvider is needs more work to wire in new services - todo: more dtos - todo: add unit tests - todo: add more integration tests
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Features;
|
|
|
|
use App\Contracts\CharacterRepository;
|
|
use App\Contracts\RequestHandler;
|
|
use App\Dto\QueryTopCharactersCommand;
|
|
use App\Http\Resources\V4\CharacterCollection;
|
|
use App\Services\QueryBuilderPaginatorService;
|
|
|
|
/**
|
|
* @implements RequestHandler<QueryTopCharactersCommand, CharacterCollection>
|
|
*/
|
|
final class QueryTopCharactersHandler implements RequestHandler
|
|
{
|
|
public function __construct(
|
|
private readonly CharacterRepository $repository,
|
|
private readonly QueryBuilderPaginatorService $paginatorService
|
|
)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param QueryTopCharactersCommand $request
|
|
* @return CharacterCollection
|
|
*/
|
|
public function handle($request): CharacterCollection
|
|
{
|
|
$requestParams = collect($request->all());
|
|
$topItemsQuery = $this->repository->topCharacters()->filter($requestParams);
|
|
|
|
$results = $this->paginatorService->paginate(
|
|
$topItemsQuery, $requestParams->get("limit"), $requestParams->get("page")
|
|
);
|
|
|
|
return new CharacterCollection($results);
|
|
}
|
|
|
|
public function requestClass(): string
|
|
{
|
|
return QueryTopCharactersCommand::class;
|
|
}
|
|
}
|