diff --git a/url1/category_n.py b/url1/category_n.py index ccd57b3d..b10a4f46 100644 --- a/url1/category_n.py +++ b/url1/category_n.py @@ -1,4 +1,4 @@ -from models import Categories, Rooms +from models import Categories, Rooms, ConciergeMiis, MiiData from room import app, db from helpers import xml_node_name, RepeatedElement @@ -6,28 +6,59 @@ @app.route("/url1/list/category/.xml") @xml_node_name("CategoryList") def list_category_n(list_id): - queried_data = ( - db.session.query(Categories, Rooms) - .filter(Categories.sp_page_id == Rooms.room_id) - .order_by(Categories.name.asc()) - .limit(64) - .all() - ) + # list_id: + # 01: All + # 02: Miis + # 03: Rooms results = [] + match list_id: + case "01": + queried_data = ( + db.session.query(Categories, Rooms) + .filter(Categories.sp_page_id == Rooms.room_id) + .order_by(Categories.name.asc()) + .limit(64) + .all() + ) - for i, category in enumerate(queried_data): - # Items must be indexed by 1. - results.append( - RepeatedElement( - { - "place": i + 1, - "categid": category[0].category_id, - "name": category[0].name, - "sppageid": category[1].room_id, - "splinktext": category[1].news, - } + for i, category in enumerate(queried_data): + # Items must be indexed by 1. + results.append( + RepeatedElement( + { + "place": i + 1, + "categid": category[0].category_id, + "name": category[0].name, + "sppageid": category[1].room_id, + "splinktext": category[1].news, + } + ) + ) + case "02": + concierge_miis = ( + db.session.query(ConciergeMiis, MiiData) + .filter(ConciergeMiis.mii_id == MiiData.mii_id) + .all() ) - ) + + for i, mii in enumerate(concierge_miis): + # Items must be indexed by 1. + results.append( + RepeatedElement( + { + "place": i + 1, + # Category ID must be 5 digits. + "categid": 20000 + mii[0].mii_id, + "name": mii[1].name, + # The following are unused in this context. + "sppageid": 0, + "splinktext": "Placeholder", + } + ) + ) + case "03": + # TODO: Rooms + pass return { "type": 3, diff --git a/url1/category_search.py b/url1/category_search.py index 41f45b21..d0ebecdf 100644 --- a/url1/category_search.py +++ b/url1/category_search.py @@ -1,18 +1,31 @@ from werkzeug import exceptions -from models import Movies +from models import Movies, ConciergeMovies from room import app from helpers import xml_node_name, RepeatedElement, current_date_and_time -@app.route("/url1/list/category/search/") +@app.route("/url1/list/category/search/") @xml_node_name("SearchMovies") def list_category_search(categ_id): - retrieved_data = ( - Movies.query.filter(Movies.category_id == categ_id) - .order_by(Movies.date_added.desc()) - .all() - ) + if categ_id < 20000: + retrieved_data = ( + Movies.query.filter(Movies.category_id == categ_id) + .order_by(Movies.date_added.desc()) + .all() + ) + elif 20000 <= categ_id <= 29999: + # Concierge Movies + retrieved_data = ( + Movies.query.filter(Movies.movie_id == ConciergeMovies.movie_id) + .filter(ConciergeMovies.mii_id == categ_id - 20000) + .order_by(Movies.date_added.desc()) + .all() + ) + else: + # TODO: This will be rooms + retrieved_data = None + results = [] if not retrieved_data: