mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
bugfix: only allow results that are within specified season/year and nulls
This commit is contained in:
parent
cd94c07232
commit
8d67c115d7
@ -4,6 +4,7 @@ namespace App\Contracts;
|
||||
|
||||
use App\Anime;
|
||||
use App\Enums\AnimeScheduleFilterEnum;
|
||||
use App\Enums\AnimeSeasonEnum;
|
||||
use App\Enums\AnimeTypeEnum;
|
||||
use Illuminate\Contracts\Database\Query\Builder as EloquentBuilder;
|
||||
use Illuminate\Support\Carbon;
|
||||
@ -41,7 +42,9 @@ interface AnimeRepository extends Repository
|
||||
public function getAiredBetween(
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?AnimeTypeEnum $type = null
|
||||
?AnimeTypeEnum $type = null,
|
||||
?AnimeSeasonEnum $season = null,
|
||||
?int $year = null
|
||||
): EloquentBuilder;
|
||||
|
||||
public function getUpcomingSeasonItems(?AnimeTypeEnum $type = null): EloquentBuilder;
|
||||
|
@ -32,7 +32,9 @@ abstract class QueryAnimeSeasonHandlerBase implements RequestHandler
|
||||
{
|
||||
$requestParams = collect($request->all());
|
||||
$type = $requestParams->has("filter") ? $request->filter : null;
|
||||
$results = $this->getSeasonItems($request, $type);
|
||||
$season = $requestParams->has("season") ? $request->season : null;
|
||||
$year = $requestParams->has("year") ? $request->year : null;
|
||||
$results = $this->getSeasonItems($request, $type, $season, $year);
|
||||
// apply sfw, kids and unapproved filters
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$results = $results->filter($requestParams);
|
||||
@ -49,7 +51,7 @@ abstract class QueryAnimeSeasonHandlerBase implements RequestHandler
|
||||
* @param ?AnimeTypeEnum $type
|
||||
* @return Builder
|
||||
*/
|
||||
protected abstract function getSeasonItems($request, ?AnimeTypeEnum $type): Builder;
|
||||
protected abstract function getSeasonItems($request, ?AnimeTypeEnum $type, ?AnimeSeasonEnum $season, ?int $year): Builder;
|
||||
|
||||
protected function getSeasonRange(int $year, AnimeSeasonEnum $season): array
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ final class QueryCurrentAnimeSeasonHandler extends QueryAnimeSeasonHandlerBase
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type): Builder
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type, ?AnimeSeasonEnum $season, ?int $year): Builder
|
||||
{
|
||||
[$season, $year] = $this->getCurrentSeason();
|
||||
/**
|
||||
@ -52,6 +52,6 @@ final class QueryCurrentAnimeSeasonHandler extends QueryAnimeSeasonHandlerBase
|
||||
* @var Carbon $to
|
||||
*/
|
||||
[$from, $to] = $this->getSeasonRange($year, $season);
|
||||
return $this->repository->getAiredBetween($from, $to, $type);
|
||||
return $this->repository->getAiredBetween($from, $to, $type, $season, $year);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Features;
|
||||
|
||||
use App\Dto\QuerySpecificAnimeSeasonCommand;
|
||||
use App\Enums\AnimeSeasonEnum;
|
||||
use App\Enums\AnimeStatusEnum;
|
||||
use App\Enums\AnimeTypeEnum;
|
||||
use Illuminate\Contracts\Database\Query\Builder;
|
||||
@ -18,7 +19,7 @@ final class QuerySpecificAnimeSeasonHandler extends QueryAnimeSeasonHandlerBase
|
||||
return QuerySpecificAnimeSeasonCommand::class;
|
||||
}
|
||||
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type): Builder
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type, ?AnimeSeasonEnum $season, ?int $year): Builder
|
||||
{
|
||||
/**
|
||||
* @var Carbon $from
|
||||
@ -27,7 +28,7 @@ final class QuerySpecificAnimeSeasonHandler extends QueryAnimeSeasonHandlerBase
|
||||
|
||||
[$from, $to] = $this->getSeasonRange($request->year, $request->season);
|
||||
|
||||
return $this->repository->getAiredBetween($from, $to, $type);
|
||||
return $this->repository->getAiredBetween($from, $to, $type, $request->season, $request->year);
|
||||
// ->where("status", "!=", AnimeStatusEnum::upcoming()->label);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Features;
|
||||
|
||||
use App\Dto\QueryUpcomingAnimeSeasonCommand;
|
||||
use App\Enums\AnimeSeasonEnum;
|
||||
use App\Enums\AnimeTypeEnum;
|
||||
use Illuminate\Contracts\Database\Query\Builder;
|
||||
|
||||
@ -16,7 +17,7 @@ final class QueryUpcomingAnimeSeasonHandler extends QueryAnimeSeasonHandlerBase
|
||||
return QueryUpcomingAnimeSeasonCommand::class;
|
||||
}
|
||||
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type): Builder
|
||||
protected function getSeasonItems($request, ?AnimeTypeEnum $type, ?AnimeSeasonEnum $season, ?int $year): Builder
|
||||
{
|
||||
return $this->repository->getUpcomingSeasonItems($type);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use App\Contracts\AnimeRepository;
|
||||
use App\Contracts\Repository;
|
||||
use App\Enums\AnimeRatingEnum;
|
||||
use App\Enums\AnimeScheduleFilterEnum;
|
||||
use App\Enums\AnimeSeasonEnum;
|
||||
use App\Enums\AnimeStatusEnum;
|
||||
use App\Enums\AnimeTypeEnum;
|
||||
use Illuminate\Contracts\Database\Query\Builder as EloquentBuilder;
|
||||
@ -115,7 +116,9 @@ final class DefaultAnimeRepository extends DatabaseRepository implements AnimeRe
|
||||
public function getAiredBetween(
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?AnimeTypeEnum $type = null
|
||||
?AnimeTypeEnum $type = null,
|
||||
?AnimeSeasonEnum $season = null,
|
||||
?int $year = null
|
||||
): EloquentBuilder
|
||||
{
|
||||
// $queryable = $this->queryable(true)->whereBetween("aired.from", [
|
||||
@ -124,7 +127,17 @@ final class DefaultAnimeRepository extends DatabaseRepository implements AnimeRe
|
||||
// ]);
|
||||
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$queryable = $this->queryable(true)->whereRaw([
|
||||
$queryable = $this->queryable(true);
|
||||
|
||||
if (!is_null($season) && !is_null($year)) {
|
||||
$premiered = ucfirst($season)." {$year}";
|
||||
$queryable = $this->queryable()
|
||||
->where("premiered", null)
|
||||
->orWhere("premiered", $premiered);
|
||||
}
|
||||
|
||||
$queryable = $this->queryable()
|
||||
->whereRaw([
|
||||
"aired.from" => [
|
||||
'$gte' => $from->toAtomString(),
|
||||
'$lte' => $to->modify("last day of this month")->toAtomString()
|
||||
@ -139,7 +152,8 @@ final class DefaultAnimeRepository extends DatabaseRepository implements AnimeRe
|
||||
}
|
||||
|
||||
public function getUpcomingSeasonItems(
|
||||
?AnimeTypeEnum $type = null
|
||||
?AnimeTypeEnum $type = null,
|
||||
?AnimeSeasonEnum $specificSeason = null
|
||||
): EloquentBuilder
|
||||
{
|
||||
$queryable = $this->queryable(true)->where("status", AnimeStatusEnum::upcoming()->label);
|
||||
|
Loading…
x
Reference in New Issue
Block a user