changeset 326:10096c5489e3

anime/db: refactor anime_season_db out
author Paper <paper@paper.us.eu.org>
date Thu, 13 Jun 2024 00:42:00 -0400
parents 78929794e7d8
children b5d6c27c308f
files Makefile.am include/core/anime_db.h include/core/anime_season.h include/core/anime_season_db.h src/core/anime_db.cc src/core/anime_season.cc src/core/anime_season_db.cc src/gui/pages/seasons.cc
diffstat 8 files changed, 15 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu Jun 13 00:36:41 2024 -0400
+++ b/Makefile.am	Thu Jun 13 00:42:00 2024 -0400
@@ -158,7 +158,6 @@
 	include/core/anime_db.h		\
 	include/core/anime.h		\
 	include/core/anime_season.h	\
-	include/core/anime_season_db.h \
 	include/core/config.h		\
 	include/core/date.h		\
 	include/core/filesystem.h			\
@@ -213,7 +212,6 @@
 	src/core/anime_db.cc		\
 	src/core/anime.cc		\
 	src/core/anime_season.cc	\
-	src/core/anime_season_db.cc \
 	src/core/config.cc		\
 	src/core/date.cc		\
 	src/core/filesystem.cc		\
--- a/include/core/anime_db.h	Thu Jun 13 00:36:41 2024 -0400
+++ b/include/core/anime_db.h	Thu Jun 13 00:42:00 2024 -0400
@@ -34,6 +34,8 @@
 
 	/* when syncing we don't want to keep deleted anime */
 	void RemoveAllUserData();
+
+	std::vector<int> GetAllAnimeForSeason(SeriesSeason season, Date::Year year);
 };
 
 extern Database db;
--- a/include/core/anime_season.h	Thu Jun 13 00:36:41 2024 -0400
+++ b/include/core/anime_season.h	Thu Jun 13 00:42:00 2024 -0400
@@ -1,7 +1,7 @@
 #ifndef MINORI_CORE_ANIME_SEASON_H_
 #define MINORI_CORE_ANIME_SEASON_H_
 
-#include "core/anime.h" /* SeriesSeason */
+#include "core/anime.h" /* Anime::SeriesSeason */
 #include "core/date.h" /* Date::Month */
 
 namespace Anime {
--- a/include/core/anime_season_db.h	Thu Jun 13 00:36:41 2024 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#ifndef MINORI_CORE_ANIME_SEASON_DB_H_
-#define MINORI_CORE_ANIME_SEASON_DB_H_
-
-#include "core/anime.h"
-#include "core/date.h"
-
-namespace Anime::Season {
-
-std::vector<int> GetAllAnimeForSeason(SeriesSeason season, Date::Year year);
-
-}
-
-#endif // MINORI_CORE_ANIME_SEASON_DB_H_
--- a/src/core/anime_db.cc	Thu Jun 13 00:36:41 2024 -0400
+++ b/src/core/anime_db.cc	Thu Jun 13 00:42:00 2024 -0400
@@ -347,6 +347,17 @@
 	}
 }
 
+std::vector<int> Database::GetAllAnimeForSeason(SeriesSeason season, Date::Year year) {
+	std::vector<int> res;
+
+	for (const auto& [id, anime] : items) {
+		if (anime.GetSeason() == season && anime.GetStartedDate().GetYear() == year)
+			res.push_back(id);
+	}
+
+	return res;
+}
+
 Database db;
 
 } // namespace Anime
--- a/src/core/anime_season.cc	Thu Jun 13 00:36:41 2024 -0400
+++ b/src/core/anime_season.cc	Thu Jun 13 00:42:00 2024 -0400
@@ -2,8 +2,6 @@
 
 namespace Anime {
 
-/* MAL has a different idea of seasons than Kitsu/AniList
- * prepare ahead of time for this discrepancy. */
 SeriesSeason GetSeasonForMonth(Date::Month month) {
 	switch (month) {
 		case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar:
--- a/src/core/anime_season_db.cc	Thu Jun 13 00:36:41 2024 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#include "core/anime_season_db.h"
-#include "core/anime.h"
-#include "core/anime_db.h"
-#include "core/date.h"
-
-namespace Anime::Season {
-
-std::vector<int> GetAllAnimeForSeason(SeriesSeason season, Date::Year year) {
-	std::vector<int> ret;
-
-	for (const auto& [id, anime] : db.items) {
-		std::optional<Date::Year> anime_year = anime.GetStartedDate().GetYear();
-		if (anime.GetSeason() == season && anime_year && anime_year.value() == year)
-			ret.push_back(id);
-	}
-
-	return ret;
-}
-
-}
--- a/src/gui/pages/seasons.cc	Thu Jun 13 00:36:41 2024 -0400
+++ b/src/gui/pages/seasons.cc	Thu Jun 13 00:42:00 2024 -0400
@@ -1,7 +1,6 @@
 #include "gui/pages/seasons.h"
 
 #include "core/anime_db.h"
-#include "core/anime_season_db.h"
 #include "core/strings.h"
 #include "gui/widgets/anime_button.h"
 #include "gui/translate/anime.h"
@@ -62,7 +61,7 @@
 
 	buttons->clear();
 
-	for (const auto& id : Anime::Season::GetAllAnimeForSeason(season_, year_)) {
+	for (const auto& id : Anime::db.GetAllAnimeForSeason(season_, year_)) {
 		QListWidgetItem* item = new QListWidgetItem;
 		AnimeButton* button = new AnimeButton(this);
 		button->SetAnime(Anime::db.items[id]);