jikan-rest/app/Features/QueryAnimeSchedulesHandler.php
pushrbx 1d3aa7b794 various hot fixes and improvements
- improved searching with low letter count
- removed the ability to order anime by type and rating
- fixed schedules endpoint's filter parameter yet again
- improved configuration
- fixed filtering anime by producers
- fixed filtering manga by magazines
- fixed search analytics in case of short search terms
2023-07-15 14:44:42 +01:00

55 lines
1.4 KiB
PHP

<?php
namespace App\Features;
use App\Contracts\AnimeRepository;
use App\Contracts\RequestHandler;
use App\Dto\QueryAnimeSchedulesCommand;
use App\Http\Resources\V4\AnimeCollection;
use App\Support\CachedData;
use Illuminate\Support\Env;
/**
* @implements RequestHandler<QueryAnimeSchedulesCommand, AnimeCollection>
*/
final class QueryAnimeSchedulesHandler implements RequestHandler
{
public function __construct(private readonly AnimeRepository $repository)
{
}
/**
* @inheritDoc
*/
public function handle($request)
{
$requestParams = collect($request->all());
$limit = $requestParams->get("limit");
$results = $this->repository->getCurrentlyAiring($request->filter);
// apply sfw, kids and unapproved filters
/** @noinspection PhpUndefinedMethodInspection */
$results = $results->filter($requestParams);
$results = $results->paginate(
$limit,
["*"],
null,
$request->page
);
$animeCollection = new AnimeCollection(
$results
);
$response = $animeCollection->response();
return $response->addJikanCacheFlags($request->getFingerPrint(), CachedData::from($animeCollection->collection));
}
/**
* @inheritDoc
*/
public function requestClass(): string
{
return QueryAnimeSchedulesCommand::class;
}
}