Skip to content

Commit

Permalink
Merge pull request #448 from jikan-me/bugfix/seasonal-102123
Browse files Browse the repository at this point in the history
bugfix: only allow results that are within specified season/year and nulls
  • Loading branch information
irfan-dahir authored Nov 3, 2023
2 parents d133290 + 4bebfc3 commit 3d822c2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/Contracts/AnimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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;
Expand Down Expand Up @@ -41,7 +42,8 @@ public function getCurrentlyAiring(
public function getAiredBetween(
Carbon $from,
Carbon $to,
?AnimeTypeEnum $type = null
?AnimeTypeEnum $type = null,
?string $premiered = null
): EloquentBuilder;

public function getUpcomingSeasonItems(?AnimeTypeEnum $type = null): EloquentBuilder;
Expand Down
2 changes: 2 additions & 0 deletions app/Features/QueryAnimeSeasonHandlerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function handle($request): JsonResponse
{
$requestParams = collect($request->all());
$type = $requestParams->has("filter") ? $request->filter : null;
$season = $requestParams->has("season") ? $request->season : null;
$year = $requestParams->has("year") ? $request->year : null;
$results = $this->getSeasonItems($request, $type);
// apply sfw, kids and unapproved filters
/** @noinspection PhpUndefinedMethodInspection */
Expand Down
4 changes: 3 additions & 1 deletion app/Features/QueryCurrentAnimeSeasonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected function getSeasonItems($request, ?AnimeTypeEnum $type): Builder
* @var Carbon $to
*/
[$from, $to] = $this->getSeasonRange($year, $season);
return $this->repository->getAiredBetween($from, $to, $type);
$premiered = ucfirst($season)." {$year}";

return $this->repository->getAiredBetween($from, $to, $type, $premiered);
}
}
4 changes: 3 additions & 1 deletion app/Features/QuerySpecificAnimeSeasonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,8 +27,9 @@ protected function getSeasonItems($request, ?AnimeTypeEnum $type): Builder
*/

[$from, $to] = $this->getSeasonRange($request->year, $request->season);
$premiered = ucfirst($request->season)." {$request->year}";

return $this->repository->getAiredBetween($from, $to, $type);
return $this->repository->getAiredBetween($from, $to, $type, $premiered);
// ->where("status", "!=", AnimeStatusEnum::upcoming()->label);
}
}
15 changes: 13 additions & 2 deletions app/Repositories/DefaultAnimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -115,7 +116,8 @@ public function getCurrentlyAiring(
public function getAiredBetween(
Carbon $from,
Carbon $to,
?AnimeTypeEnum $type = null
?AnimeTypeEnum $type = null,
?string $premiered = null
): EloquentBuilder
{
// $queryable = $this->queryable(true)->whereBetween("aired.from", [
Expand All @@ -124,7 +126,16 @@ public function getAiredBetween(
// ]);

/** @noinspection PhpParamsInspection */
$queryable = $this->queryable(true)->whereRaw([
$queryable = $this->queryable(true);

if ($premiered !== null) {
$queryable = $queryable
->where("premiered", null)
->orWhere("premiered", $premiered);
}

$queryable = $queryable
->whereRaw([
"aired.from" => [
'$gte' => $from->toAtomString(),
'$lte' => $to->modify("last day of this month")->toAtomString()
Expand Down

0 comments on commit 3d822c2

Please sign in to comment.