Filter out routes with no encounters for the active game
Routes are shared per version group, so game-exclusive locations (e.g.,
Black City, White Forest) appeared for both games. Now the /games/{id}/routes
endpoint excludes routes that have no encounters for the requested game,
in both flat and hierarchical modes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user