From 66912a0b717cf31da96618fbe60e1b8eee17040f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 3 Apr 2026 15:19:15 +0000 Subject: [PATCH] fix: filtre content_type, doublons seasonaux, et is_admin manquant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bug 1: Ajout du champ 'type' dans les dict de AnimeReleasesFetcher (get_seasonal_anime, get_scheduled_anime, get_top_anime, search_anime) et dans _get_fallback_recommendations pour que le filtre content_type fonctionne correctement - Bug 2: Déduplication par mal_id dans get_seasonal_anime() pour éviter les doublons retournés par l'API Jikan - Bug 3: Ajout de is_admin dans get_current_user_from_token(), get_optional_user(), le constructeur User du register, et la réponse /me --- app/recommendation_engine.py | 5 +++++ app/recommendations.py | 21 +++++++++++++++------ app/routers/router_auth.py | 4 ++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/recommendation_engine.py b/app/recommendation_engine.py index 76e918f..62dc0a2 100644 --- a/app/recommendation_engine.py +++ b/app/recommendation_engine.py @@ -285,6 +285,7 @@ class RecommendationEngine: 'score': 9.09, 'episodes': 64, 'status': 'Finished Airing', + 'type': 'TV', 'genres': ['Action', 'Adventure', 'Fantasy'], 'synopsis': 'Two brothers lose their mother to an incurable disease. With the power of alchemy, they use taboo knowledge to resurrect her. The process fails, and as a toll for crossing into the realm of God, they lose their bodies.', 'images': {}, @@ -298,6 +299,7 @@ class RecommendationEngine: 'score': 8.51, 'episodes': 75, 'status': 'Finished Airing', + 'type': 'TV', 'genres': ['Action', 'Drama', 'Fantasy'], 'synopsis': 'Centuries ago, mankind was slaughtered to near extinction by monstrous humanoid creatures called titans. To protect what remains, humanity built walls and lived peacefully for a hundred years.', 'images': {}, @@ -311,6 +313,7 @@ class RecommendationEngine: 'score': 8.63, 'episodes': 37, 'status': 'Finished Airing', + 'type': 'TV', 'genres': ['Mystery', 'Police', 'Psychological'], 'synopsis': 'A shinigami, as a god of death, can kill any person—provided they see their victim\'s face and write their victim\'s name in a notebook called a Death Note.', 'images': {}, @@ -324,6 +327,7 @@ class RecommendationEngine: 'score': 8.48, 'episodes': 26, 'status': 'Finished Airing', + 'type': 'TV', 'genres': ['Action', 'Adventure', 'Supernatural'], 'synopsis': 'It is the Taisho Period in Japan. Tanjiro, a kindhearted boy who sells charcoal for a living, finds his family slaughtered by a demon. To make matters worse, his younger sister Nezuko is turned into a demon.', 'images': {}, @@ -337,6 +341,7 @@ class RecommendationEngine: 'score': 8.35, 'episodes': 24, 'status': 'Finished Airing', + 'type': 'TV', 'genres': ['Action', 'Supernatural'], 'synopsis': 'Yuji Itadori is a boy with tremendous physical strength, though he lives a completely ordinary high school life. One day, to save a friend who has been attacked by curses, he eats the finger of a curse.', 'images': {}, diff --git a/app/recommendations.py b/app/recommendations.py index 98c134e..1960753 100644 --- a/app/recommendations.py +++ b/app/recommendations.py @@ -92,7 +92,12 @@ class AnimeReleasesFetcher: data = response.json() anime_list = [] - for anime in data.get('data', [])[:20]: + seen_mal_ids = set() + for anime in data.get('data', []): + mal_id = anime.get('mal_id') + if not mal_id or mal_id in seen_mal_ids: + continue + seen_mal_ids.add(mal_id) anime_list.append({ 'title': anime.get('title', ''), 'title_japanese': anime.get('title_japanese', ''), @@ -105,9 +110,10 @@ class AnimeReleasesFetcher: 'cover_image': self._extract_cover_image(anime), 'images': anime.get('images', {}), 'url': anime.get('url', ''), - 'mal_id': anime.get('mal_id') + 'mal_id': mal_id, + 'type': anime.get('type', '') }) - return anime_list + return anime_list[:20] except Exception as e: logger.error(f"Error fetching seasonal anime: {e}", exc_info=True) return [] @@ -143,7 +149,8 @@ class AnimeReleasesFetcher: 'cover_image': self._extract_cover_image(anime), 'broadcast': anime.get('broadcast', {}), 'url': anime.get('url', ''), - 'mal_id': anime.get('mal_id') + 'mal_id': anime.get('mal_id'), + 'type': anime.get('type', '') }) return anime_list except Exception as e: @@ -178,7 +185,8 @@ class AnimeReleasesFetcher: 'cover_image': self._extract_cover_image(anime), 'images': anime.get('images', {}), 'url': anime.get('url', ''), - 'mal_id': anime.get('mal_id') + 'mal_id': anime.get('mal_id'), + 'type': anime.get('type', '') }) return anime_list except Exception as e: @@ -209,7 +217,8 @@ class AnimeReleasesFetcher: 'cover_image': self._extract_cover_image(anime), 'images': anime.get('images', {}), 'url': anime.get('url', ''), - 'mal_id': anime.get('mal_id') + 'mal_id': anime.get('mal_id'), + 'type': anime.get('type', '') }) return anime_list except Exception as e: diff --git a/app/routers/router_auth.py b/app/routers/router_auth.py index b029f43..888d797 100644 --- a/app/routers/router_auth.py +++ b/app/routers/router_auth.py @@ -54,6 +54,7 @@ async def get_current_user_from_token( email=user.email, full_name=user.full_name, is_active=user.is_active, + is_admin=user.is_admin, created_at=user.created_at, last_login=user.last_login, ) @@ -79,6 +80,7 @@ async def get_optional_user( email=user.email, full_name=user.full_name, is_active=user.is_active, + is_admin=user.is_admin, created_at=user.created_at, last_login=user.last_login, ) @@ -108,6 +110,7 @@ async def register(user_data: UserCreate): email=user.email, full_name=user.full_name, is_active=user.is_active, + is_admin=user.is_admin, created_at=user.created_at, last_login=user.last_login, ) @@ -174,6 +177,7 @@ async def get_me(current_user: User = Depends(get_current_user_from_token)): "email": current_user.email, "full_name": current_user.full_name, "is_active": current_user.is_active, + "is_admin": current_user.is_admin, "created_at": current_user.created_at, "last_login": current_user.last_login, }