diff --git a/.beans/nuzlocke-tracker-cftf--filter-out-routes-with-no-encounters-for-active-ga.md b/.beans/nuzlocke-tracker-cftf--filter-out-routes-with-no-encounters-for-active-ga.md new file mode 100644 index 0000000..6970211 --- /dev/null +++ b/.beans/nuzlocke-tracker-cftf--filter-out-routes-with-no-encounters-for-active-ga.md @@ -0,0 +1,11 @@ +--- +# nuzlocke-tracker-cftf +title: Filter out routes with no encounters for active game +status: completed +type: task +priority: normal +created_at: 2026-02-14T14:38:05Z +updated_at: 2026-02-14T14:38:19Z +--- + +Route orders are per version group, so both games in a pair share the same route list. Routes with no encounters for the active game should be filtered out in the list_game_routes endpoint. \ No newline at end of file diff --git a/backend/src/app/api/games.py b/backend/src/app/api/games.py index 33ac589..67d747c 100644 --- a/backend/src/app/api/games.py +++ b/backend/src/app/api/games.py @@ -169,7 +169,11 @@ async def list_game_routes( } if flat: - return [route_to_dict(r) for r in all_routes] + return [ + route_to_dict(r) + for r in all_routes + if any(re.game_id == game_id for re in r.route_encounters) + ] # Build hierarchical structure # Group children by parent_route_id @@ -180,16 +184,24 @@ async def list_game_routes( if route.parent_route_id is None: top_level_routes.append(route) else: - children_by_parent.setdefault(route.parent_route_id, []).append( - route_to_dict(route) - ) + # Only include children that have encounters for this game + if any(re.game_id == game_id for re in route.route_encounters): + children_by_parent.setdefault(route.parent_route_id, []).append( + route_to_dict(route) + ) # Build response with nested children + # Only include top-level routes that have their own encounters or remaining children response = [] for route in top_level_routes: - route_dict = route_to_dict(route) - route_dict["children"] = children_by_parent.get(route.id, []) - response.append(route_dict) + children = children_by_parent.get(route.id, []) + has_own_encounters = any( + re.game_id == game_id for re in route.route_encounters + ) + if has_own_encounters or children: + route_dict = route_to_dict(route) + route_dict["children"] = children + response.append(route_dict) return response