@@ -90,8 +90,8 @@ def apps_by_category(category):
9090 return generate_app_response (apps )
9191
9292
93- @api .route ('/apps/collection/<collection >/<app_type>' )
94- def apps_by_collection (collection , app_type ):
93+ @api .route ('/apps/collection/<slug >/<app_type>' )
94+ def apps_by_collection (slug , app_type ):
9595 hw = request .args .get ('hardware' , 'basalt' )
9696 type_mapping = {
9797 'watchapps-and-companions' : 'watchapp' ,
@@ -103,15 +103,18 @@ def apps_by_collection(collection, app_type):
103103 abort (404 )
104104 app_type = type_mapping [app_type ]
105105 sort_override = None
106- if collection == 'all' :
106+ if slug == 'all' :
107107 apps = App .query .filter (App .type == app_type , ~ generated_filter (), global_filter (hw ))
108- elif collection == 'most-loved' :
108+ elif slug == 'most-loved' :
109109 apps = App .query .filter (App .type == app_type , global_filter (hw ))
110110 sort_override = 'hearts'
111- elif collection == 'all-generated' :
111+ elif slug == 'all-generated' :
112112 apps = App .query .filter (App .type == app_type , generated_filter (), global_filter (hw ))
113113 else :
114- apps = Collection .query .filter_by (collection = collection ).apps .filter_by (type = app_type ).filter (global_filter (hw ))
114+ collection = Collection .query .filter_by (slug = slug ).one_or_none ()
115+ if collection is None :
116+ abort (404 )
117+ apps = collection .apps .filter_by (type = app_type ).filter (global_filter (hw ))
115118 return generate_app_response (apps , sort_override = sort_override )
116119
117120
@@ -205,7 +208,7 @@ def home(home_type):
205208 'slug' : collection .slug ,
206209 'application_ids' : [x .id for x in collection .apps .distinct ().limit (7 )],
207210 'links' : {
208- 'apps' : url_for ('api.apps_by_collection' , collection = collection .slug , app_type = home_type )
211+ 'apps' : url_for ('api.apps_by_collection' , slug = collection .slug , app_type = home_type )
209212 },
210213 } for collection in collections ), {
211214 'name' : f'Most Loved' ,
@@ -217,7 +220,7 @@ def home(home_type):
217220 .distinct ()
218221 .limit (7 )],
219222 'links' : {
220- 'apps' : url_for ('api.apps_by_collection' , collection = 'most-loved' , app_type = home_type ),
223+ 'apps' : url_for ('api.apps_by_collection' , slug = 'most-loved' , app_type = home_type ),
221224 }
222225 }, {
223226 'name' : f'All { "Watchfaces" if app_type == "watchface" else "Watchapps" } ' ,
@@ -229,7 +232,7 @@ def home(home_type):
229232 .distinct ()
230233 .limit (7 )],
231234 'links' : {
232- 'apps' : url_for ('api.apps_by_collection' , collection = 'all' , app_type = home_type ),
235+ 'apps' : url_for ('api.apps_by_collection' , slug = 'all' , app_type = home_type ),
233236 }
234237 }, * ([{
235238 'name' : f'Generated Watchfaces' ,
@@ -241,7 +244,7 @@ def home(home_type):
241244 .distinct ()
242245 .limit (7 )],
243246 'links' : {
244- 'apps' : url_for ('api.apps_by_collection' , collection = 'all-generated' , app_type = home_type ),
247+ 'apps' : url_for ('api.apps_by_collection' , slug = 'all-generated' , app_type = home_type ),
245248 }
246249 }] if app_type == 'watchface' else [])],
247250 }
0 commit comments