From 705e0fbf36ce099b0b6551f52289d9076807a27f Mon Sep 17 00:00:00 2001 From: pushrbx Date: Mon, 28 Oct 2024 16:22:04 +0100 Subject: [PATCH 1/4] fixed season endpoint's continuing flag #555 --- app/Repositories/DefaultAnimeRepository.php | 38 ++++++++++++++++----- tests/Integration/SeasonControllerTest.php | 35 +++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/app/Repositories/DefaultAnimeRepository.php b/app/Repositories/DefaultAnimeRepository.php index ffbf103d..98436297 100644 --- a/app/Repositories/DefaultAnimeRepository.php +++ b/app/Repositories/DefaultAnimeRepository.php @@ -167,19 +167,39 @@ public function getItemsBySeason( $finalFilter['$or'][] = [ // note: this expression only works with mongodb version 5.0.0 or higher '$expr' => [ - '$lte' => [ + '$and' => [ [ - '$dateDiff' => [ - 'startDate' => [ - '$dateFromString' => [ - 'dateString' => '$aired.from' + '$lte' => [ + [ + '$dateDiff' => [ + 'startDate' => [ + '$dateFromString' => [ + 'dateString' => '$aired.from' + ] + ], + 'endDate' => new UTCDateTime($from), + 'unit' => 'month' ] ], - 'endDate' => new UTCDateTime($from), - 'unit' => 'month' - ] + 3 // there are 3 months in a season, so anything that started in 3 months or less will be included + ], ], - 3 // there are 3 months in a season, so anything that started in 3 months or less will be included + [ + '$gt' => [ + [ + '$dateDiff' => [ + 'startDate' => [ + '$dateFromString' => [ + 'dateString' => '$aired.from' + ] + ], + 'endDate' => new UTCDateTime($from), + 'unit' => 'month' + ] + ], + 0 + ] + ] ] ], 'aired.to' => null, diff --git a/tests/Integration/SeasonControllerTest.php b/tests/Integration/SeasonControllerTest.php index 6d6a752e..ffcde268 100644 --- a/tests/Integration/SeasonControllerTest.php +++ b/tests/Integration/SeasonControllerTest.php @@ -190,4 +190,39 @@ public function testShouldNotIncludeContinuingItemsByDefault() $this->assertIsArray($content["data"]); $this->assertCount(2, $content["data"]); } + + public function testShouldNotIncludeNewlyStartedSeasonOfAnimeInPreviousSeasons() + { + Carbon::setTestNow(Carbon::parse("2024-10-26")); + $f = Anime::factory(1); + $startDate = "2024-10-02"; + $carbonStartDate = Carbon::parse($startDate); + $state = $f->serializeStateDefinition([ + "aired" => new CarbonDateRange($carbonStartDate, null) + ]); + $state["aired"]["string"] = "Oct 2, 2024 to ?"; + $state["airing"] = true; + $state["status"] = "Currently Airing"; + $state["premiered"] = "Fall 2024"; + $state["mal_id"] = 54857; + $state["title"] = "Re:Zero kara Hajimeru Isekai Seikatsu 3rd Season"; + $state["episodes"] = 16; + $state["type"] = "TV"; + $state["duration"] = "23 min per ep"; + $state["score"] = 8.9; + $f->create($state); + + $content = $this->getJsonResponse([], "/v4/seasons/now?filter=tv&continuing&page=1"); + $this->seeStatusCode(200); + $this->assertCount(1, $content["data"]); + + $content = $this->getJsonResponse([], "/v4/seasons/2024/summer?filter=tv&continuing&page=1"); + $this->seeStatusCode(200); + $this->assertCount(0, $content["data"]); + + $content = $this->getJsonResponse([], "/v4/seasons/2024/spring?filter=tv&continuing&page=1"); + $this->seeStatusCode(200); + $this->assertCount(0, $content["data"]); + Carbon::setTestNow(); + } } From 9553c2e7f91d9a6e5095f438d41e51723147b2de Mon Sep 17 00:00:00 2001 From: pushrbx Date: Mon, 28 Oct 2024 16:22:48 +0100 Subject: [PATCH 2/4] fixed search index collection schema for producers --- app/Producers.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/Producers.php b/app/Producers.php index f46216d8..dd5441c0 100644 --- a/app/Producers.php +++ b/app/Producers.php @@ -72,6 +72,33 @@ public function toSearchableArray(): array ]; } + public function getCollectionSchema(): array + { + return [ + 'name' => $this->searchableAs(), + 'fields' => [ + [ + 'name' => '.*', + 'type' => 'auto', + ], + [ + 'name' => 'titles', + 'type' => 'string', + 'optional' => false, + 'infix' => true, + 'sort' => true + ], + [ + 'name' => 'url', + 'type' => 'string', + 'optional' => false, + 'infix' => true, + 'sort' => true + ], + ] + ]; + } + public function typesenseQueryBy(): array { return [ From 2272ed17c4f6a99269b031c9a696b1ab5efe89ff Mon Sep 17 00:00:00 2001 From: pushrbx Date: Fri, 8 Nov 2024 19:36:45 +0000 Subject: [PATCH 3/4] added typesense collection schema for Magazine model --- app/Magazine.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/Magazine.php b/app/Magazine.php index 513fdb41..8c23553b 100644 --- a/app/Magazine.php +++ b/app/Magazine.php @@ -72,6 +72,33 @@ public function toSearchableArray(): array ]; } + public function getCollectionSchema(): array + { + return [ + 'name' => $this->searchableAs(), + 'fields' => [ + [ + 'name' => '.*', + 'type' => 'auto', + ], + [ + 'name' => 'titles', + 'type' => 'string', + 'optional' => false, + 'infix' => true, + 'sort' => true + ], + [ + 'name' => 'url', + 'type' => 'string', + 'optional' => false, + 'infix' => true, + 'sort' => true + ], + ] + ]; + } + public function typesenseQueryBy(): array { return [ From 8c6398dd58c1308a4683eec55de74ecb4805c825 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Fri, 8 Nov 2024 19:46:07 +0000 Subject: [PATCH 4/4] revert changes to magazine model --- app/Magazine.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/app/Magazine.php b/app/Magazine.php index 8c23553b..513fdb41 100644 --- a/app/Magazine.php +++ b/app/Magazine.php @@ -72,33 +72,6 @@ public function toSearchableArray(): array ]; } - public function getCollectionSchema(): array - { - return [ - 'name' => $this->searchableAs(), - 'fields' => [ - [ - 'name' => '.*', - 'type' => 'auto', - ], - [ - 'name' => 'titles', - 'type' => 'string', - 'optional' => false, - 'infix' => true, - 'sort' => true - ], - [ - 'name' => 'url', - 'type' => 'string', - 'optional' => false, - 'infix' => true, - 'sort' => true - ], - ] - ]; - } - public function typesenseQueryBy(): array { return [