diff --git a/api/code/metroplanner_api/v1/endpoints/_plans.py b/api/code/metroplanner_api/v1/endpoints/_plans.py index b0991be..06c856c 100644 --- a/api/code/metroplanner_api/v1/endpoints/_plans.py +++ b/api/code/metroplanner_api/v1/endpoints/_plans.py @@ -11,132 +11,120 @@ router = APIRouter() -@router.post("/") +@router.post("/", status_code=201) def post_plan( plan_data: type_definitions.CreatePlan, req: Request, sub: str = Depends(check_auth) -) -> type_definitions.PlanInDB: - try: - print("Received request to create a new plan. Validating JSON data...") - print("Data successfully validated:", plan_data) - - db = ENV.database - - new_plan_data = { - "planName": plan_data["planName"], - "planDescription": plan_data["planName"], - "forkedFrom": None, - "deleted": None, - "createdAt": (now := datetime.now().isoformat()), - "lastModifiedAt": now, - "likeCount": 0, - "ownedBy": sub, - "colorTheme": (theme := "colorful-dl"), - "currentNumberOfEdges": 0, - "currentNumberOfLines": 0, - "currentNumberOfNodes": 0, - "currentNumberOfLabels": 0, - } - - print("initial data for new plan:", new_plan_data) +) -> type_definitions.PlanId: + print("Received request to create a new plan. Validating JSON data...") + print("Data successfully validated:", plan_data) - if fork_from := plan_data.get("forkFrom", None): - print("Plan is to be forked from", fork_from) - if shortlink := fork_from.get("shortlink", None): - link_data = db.links.find_one({"_id": shortlink}) + db = ENV.database - if link_data and link_data["active"]: - planid = link_data["plan"] - else: - return responses.gone_410() + new_plan_data = { + "planName": plan_data["planName"], + "planDescription": plan_data["planName"], + "forkedFrom": None, + "deleted": None, + "createdAt": (now := datetime.now().isoformat()), + "lastModifiedAt": now, + "likeCount": 0, + "ownedBy": sub, + "colorTheme": (theme := "colorful-dl"), + "currentNumberOfEdges": 0, + "currentNumberOfLines": 0, + "currentNumberOfNodes": 0, + "currentNumberOfLabels": 0, + } + + print("initial data for new plan:", new_plan_data) + + if fork_from := plan_data.get("forkFrom", None): + print("Plan is to be forked from", fork_from) + if shortlink := fork_from.get("shortlink", None): + link_data = db.links.find_one({"_id": shortlink}) + + if link_data and link_data["active"]: + planid = link_data["plan"] else: - planid = BsonObjectId(fork_from.get("planID", None)) + raise responses.gone_410() + else: + planid = BsonObjectId(fork_from.get("planID", None)) - plan_details = db.plans.find_one( - { - "_id": planid, - }, - ) + plan_details = db.plans.find_one( + { + "_id": planid, + }, + ) - if plan_details: - if shortlink or plan_details["ownedBy"] == sub: - planstateid = ( - BsonObjectId(fork_from["planstateID"]) - if not shortlink - else plan_details["currentState"] - ) + if plan_details: + if shortlink or plan_details["ownedBy"] == sub: + planstateid = ( + BsonObjectId(fork_from["planstateID"]) + if not shortlink + else plan_details["currentState"] + ) - planstate = db.planstates.find_one( - { - "_id": planstateid, - }, - { - "_id": 0, - }, - ) + planstate = db.planstates.find_one( + { + "_id": planstateid, + }, + { + "_id": 0, + }, + ) - if planstate: - insert_planstate_res = db.planstates.insert_one(planstate) - new_plan_data["currentNumberOfEdges"] = planstate[ - "numberOfEdges" - ] - new_plan_data["currentNumberOfLines"] = planstate[ - "numberOfLines" - ] - new_plan_data["currentNumberOfNodes"] = planstate[ - "numberOfNodes" - ] - new_plan_data["currentNumberOfLabels"] = planstate[ - "numberOfLabels" - ] - new_plan_data["colorTheme"] = plan_details["colorTheme"] - else: - return responses.gone_410() + if planstate: + insert_planstate_res = db.planstates.insert_one(planstate) + new_plan_data["currentNumberOfEdges"] = planstate["numberOfEdges"] + new_plan_data["currentNumberOfLines"] = planstate["numberOfLines"] + new_plan_data["currentNumberOfNodes"] = planstate["numberOfNodes"] + new_plan_data["currentNumberOfLabels"] = planstate["numberOfLabels"] + new_plan_data["colorTheme"] = plan_details["colorTheme"] else: - raise responses.unauthorized_401() + raise responses.gone_410() else: - return responses.gone_410() + raise responses.unauthorized_401() else: - print("Creating plan from scratch") - insert_planstate_res = db.planstates.insert_one( - { - "createdAt": now, - "numberOfEdges": 0, - "numberOfLines": 0, - "numberOfNodes": 0, - "numberOfLabels": 0, - "nodes": {}, - "lines": [], - "labels": {}, - "globalOffsetX": 0, - "globalOffsetY": 0, - "planHeight": 10, - "planWidth": 10, - "colorTheme": theme, - } - ) - print("Created plan, result:", insert_planstate_res) - new_plan_data["currentState"] = ( - new_planstateid := insert_planstate_res.inserted_id - ) - new_plan_data["history"] = [new_planstateid] - - insert_res = db.plans.insert_one(new_plan_data) - print("After insertion, this is the result:", insert_res) - - new_plan_id = insert_res.inserted_id - Σ = "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ3456789-" - db.links.insert_one( + raise responses.gone_410() + else: + print("Creating plan from scratch") + insert_planstate_res = db.planstates.insert_one( { - "_id": "".join([random.choice(Σ) for _ in range(8)]), - "plan": new_plan_id, - "active": True, + "createdAt": now, + "numberOfEdges": 0, + "numberOfLines": 0, + "numberOfNodes": 0, + "numberOfLabels": 0, + "nodes": {}, + "lines": [], + "labels": {}, + "globalOffsetX": 0, + "globalOffsetY": 0, + "planHeight": 10, + "planWidth": 10, + "colorTheme": theme, } ) + print("Created plan, result:", insert_planstate_res) + new_plan_data["currentState"] = ( + new_planstateid := insert_planstate_res.inserted_id + ) + new_plan_data["history"] = [new_planstateid] + + insert_res = db.plans.insert_one(new_plan_data) + print("After insertion, this is the result:", insert_res) + + new_plan_id = insert_res.inserted_id + Σ = "abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ3456789-" + db.links.insert_one( + { + "_id": "".join([random.choice(Σ) for _ in range(8)]), + "plan": new_plan_id, + "active": True, + } + ) - return responses.created_201({"planId": str(new_plan_id)}) - except Exception as e: - print("Operation failed", e) - return responses.internal_server_error_500() + return {"planId": str(new_plan_id)} @router.patch("/{plan_id}") @@ -146,65 +134,61 @@ def patch_plan( req: Request, sub: str = Depends(check_auth), ) -> type_definitions.PlanInDB: - try: - db = ENV.database - plan_details = db.plans.find_one( + db = ENV.database + plan_details = db.plans.find_one( + { + "_id": plan_id, + }, + { + "_id": 0, + "ownedBy": 1, + }, + ) + + if plan_details["ownedBy"] == sub: + set_data = {} + + for k in [ + "planName", + "planDescription", + "currentState", + "currentColorTheme", + ]: + if k == "currentColorTheme": + print("Can't change color theme atm") + return responses.not_implemented_501() + if k == "currentState": + new_id = BsonObjectId(plan_data["currentState"]) + get_planstate_result = db.planstates.find_one( + {"_id": new_id}, {"_id": 1} + ) + if get_planstate_result: + print( + "Found corresponding planstate!", + get_planstate_result, + ) + else: + print( + "Did not find corresponding planstate!", + get_planstate_result, + ) + return responses.bad_request_400() + set_data[k] = new_id + else: + set_data[k] = plan_data[k] + + set_data["lastModifiedAt"] = datetime.now().isoformat() + + db.plans.update_one( { "_id": plan_id, }, { - "_id": 0, - "ownedBy": 1, + "$set": set_data, }, ) - - if plan_details["ownedBy"] == sub: - set_data = {} - - for k in [ - "planName", - "planDescription", - "currentState", - "currentColorTheme", - ]: - if k == "currentColorTheme": - print("Can't change color theme atm") - return responses.not_implemented_501() - if k == "currentState": - new_id = BsonObjectId(plan_data["currentState"]) - get_planstate_result = db.planstates.find_one( - {"_id": new_id}, {"_id": 1} - ) - if get_planstate_result: - print( - "Found corresponding planstate!", - get_planstate_result, - ) - else: - print( - "Did not find corresponding planstate!", - get_planstate_result, - ) - return responses.bad_request_400() - set_data[k] = new_id - else: - set_data[k] = plan_data[k] - - set_data["lastModifiedAt"] = datetime.now().isoformat() - - db.plans.update_one( - { - "_id": plan_id, - }, - { - "$set": set_data, - }, - ) - else: - return responses.unauthorized_401() - except Exception as e: - print("Patching plan failed", e) - return responses.internal_server_error_500() + else: + return responses.unauthorized_401() @router.get("/{plan_id}") @@ -291,10 +275,10 @@ def get_plan( plan_details else: - return responses.unauthorized_401() + raise responses.unauthorized_401() -@router.delete("/{plan_id}") +@router.delete("/{plan_id}", status_code=204) def delete_plan( plan_id: type_definitions.ObjectId, req: Request, sub: str = Depends(check_auth) ): @@ -309,16 +293,18 @@ def delete_plan( ) print("Found plan Details: ", plan_details) + if plan_details: + if plan_details["ownedBy"] == sub: + if plan_details.get("deleted", None) is not None: + raise responses.gone_410() + db.plans.update_one( + {"_id": plan_id}, {"$set": {"deleted": datetime.now().isoformat()}} + ) - if plan_details["ownedBy"] == sub: - if plan_details.get("deleted", None) is not None: - return responses.gone_410() - db.plans.update_one( - {"_id": plan_id}, {"$set": {"deleted": datetime.now().isoformat()}} - ) - - shortlinks = list(db.links.find({"plan": plan_id})) + shortlinks = list(db.links.find({"plan": plan_id})) - for shortlink in shortlinks: - print("Shortlink", shortlink, "will be removed") - db.links.delete_one({"_id": shortlink["_id"]}) + for shortlink in shortlinks: + print("Shortlink", shortlink, "will be removed") + db.links.delete_one({"_id": shortlink["_id"]}) + else: + raise responses.gone_410() diff --git a/api/code/metroplanner_api/v1/endpoints/_planstates.py b/api/code/metroplanner_api/v1/endpoints/_planstates.py index 8e36483..80cbd69 100644 --- a/api/code/metroplanner_api/v1/endpoints/_planstates.py +++ b/api/code/metroplanner_api/v1/endpoints/_planstates.py @@ -16,111 +16,100 @@ def post_planstate( req: Request, sub: str = Depends(check_auth), ) -> type_definitions.PlanInDB: - try: - # make_current = "makeCurrent" in self.event.get("queryStringParameters", {}) - db = ENV.database - plan_details = db.plans.find_one( + # make_current = "makeCurrent" in self.event.get("queryStringParameters", {}) + db = ENV.database + plan_details = db.plans.find_one( + {"_id": type_definitions.ObjectId(plan_id)}, + { + "_id": 0, + "ownedBy": 1, + }, + ) + + if plan_details["ownedBy"] == sub: + number_of_edges = 0 + + for ln in planstate_data["lines"]: + for cons in ln["connections"]: + number_of_edges += len(cons["nodes"]) + + planstate_data["numberOfEdges"] = number_of_edges + planstate_data["numberOfLines"] = len(planstate_data["lines"]) + planstate_data["numberOfNodes"] = len(planstate_data["nodes"]) + planstate_data["numberOfLabels"] = len(planstate_data["labels"]) + + planstate_data["createdAt"] = datetime.now().isoformat() + + created_result = db.planstates.insert_one(planstate_data) + print("Created planstate:", created_result) + + set_plan_data = { + "lastModifiedAt": planstate_data["createdAt"], + } + + if planstate_data.make_current: + set_plan_data["currentState"] = (created_result.inserted_id,) + set_plan_data["numberOfEdges"] = planstate_data["numberOfEdges"] + set_plan_data["numberOfLines"] = planstate_data["numberOfLines"] + set_plan_data["numberOfNodes"] = planstate_data["numberOfNodes"] + set_plan_data["numberOfLabels"] = planstate_data["numberOfLabels"] + + db.plans.update_one( {"_id": type_definitions.ObjectId(plan_id)}, { - "_id": 0, - "ownedBy": 1, + "$push": { + "history": created_result.inserted_id, + }, + "$set": set_plan_data, }, ) - if plan_details["ownedBy"] == sub: - number_of_edges = 0 - - for ln in planstate_data["lines"]: - for cons in ln["connections"]: - number_of_edges += len(cons["nodes"]) - - planstate_data["numberOfEdges"] = number_of_edges - planstate_data["numberOfLines"] = len(planstate_data["lines"]) - planstate_data["numberOfNodes"] = len(planstate_data["nodes"]) - planstate_data["numberOfLabels"] = len(planstate_data["labels"]) - - planstate_data["createdAt"] = datetime.now().isoformat() - - created_result = db.planstates.insert_one(planstate_data) - print("Created planstate:", created_result) - - set_plan_data = { - "lastModifiedAt": planstate_data["createdAt"], - } - - if planstate_data.make_current: - set_plan_data["currentState"] = (created_result.inserted_id,) - set_plan_data["numberOfEdges"] = planstate_data["numberOfEdges"] - set_plan_data["numberOfLines"] = planstate_data["numberOfLines"] - set_plan_data["numberOfNodes"] = planstate_data["numberOfNodes"] - set_plan_data["numberOfLabels"] = planstate_data["numberOfLabels"] - - db.plans.update_one( - {"_id": type_definitions.ObjectId(plan_id)}, - { - "$push": { - "history": created_result.inserted_id, - }, - "$set": set_plan_data, - }, - ) - - return responses.created_201( - {"planstateID": str(created_result.inserted_id), **planstate_data} - ) - else: - return responses.unauthorized_401() - except Exception as e: - print("error creating planstate:", e) - return responses.internal_server_error_500() + return {"planstateID": str(created_result.inserted_id), **planstate_data} + else: + raise responses.unauthorized_401() @router.get("/{plan_id}/_planstates/{planstate_id}") def get_planstate( plan_id, planstate_id, req: Request, sub: str = Depends(check_auth) ) -> type_definitions.PlanstateInDB: - try: - db = ENV.database - plan_details = db.plans.find_one( - {"_id": type_definitions.ObjectId(plan_id)}, - {"_id": 0, "ownedBy": 1, "history": 1}, - ) + db = ENV.database + plan_details = db.plans.find_one( + {"_id": type_definitions.ObjectId(plan_id)}, + {"_id": 0, "ownedBy": 1, "history": 1}, + ) - if plan_details: - if plan_details["ownedBy"] == sub: - if type_definitions.ObjectId(planstate_id) in plan_details["history"]: - planstate = db.planstates.find_one( - {"_id": type_definitions.ObjectId(planstate_id)}, - {"_id": 0}, - ) + if plan_details: + if plan_details["ownedBy"] == sub: + if type_definitions.ObjectId(planstate_id) in plan_details["history"]: + planstate = db.planstates.find_one( + {"_id": type_definitions.ObjectId(planstate_id)}, + {"_id": 0}, + ) - if planstate: - print("Found planstate with id", planstate_id) - return planstate - else: - print( - f"Planstate with id {planstate_id} not found", - planstate, - ) - return responses.gone_410() + if planstate: + print("Found planstate with id", planstate_id) + return planstate else: print( - "Requested Planstate not in plan history", - planstate_id, - plan_details["history"], + f"Planstate with id {planstate_id} not found", + planstate, ) - return responses.gone_410() + raise responses.gone_410() else: print( - "ownedBy doesn't match sub", - plan_details["ownedBy"], - sub, + "Requested Planstate not in plan history", + planstate_id, + plan_details["history"], ) - return responses.unauthorized_401() + raise responses.gone_410() else: - print(f"Plan with id {plan_id} not found", plan_details) - return responses.gone_410() - - except Exception as e: - print("Exception during GET Planstate:", e) - return responses.internal_server_error_500() + print( + "ownedBy doesn't match sub", + plan_details["ownedBy"], + sub, + ) + raise responses.unauthorized_401() + else: + print(f"Plan with id {plan_id} not found", plan_details) + raise responses.gone_410() diff --git a/api/code/metroplanner_api/v1/endpoints/_user.py b/api/code/metroplanner_api/v1/endpoints/_user.py index 24d3424..8cc1202 100644 --- a/api/code/metroplanner_api/v1/endpoints/_user.py +++ b/api/code/metroplanner_api/v1/endpoints/_user.py @@ -84,23 +84,16 @@ def get_user( def patch_user( user_data: type_definitions.UpdateUser, req: Request, sub: str = Depends(check_auth) ) -> type_definitions.UserInDB: - try: - db = ENV.database - updated_result = db.users.find_one_and_update( - { - "_id": sub, - }, - {"$set": user_data.get_existing_fields()}, - return_document=ReturnDocument.AFTER, - ) - print("Updated result:", updated_result) - if updated_result: - updated_result - else: - return responses.internal_server_error_500() - except KeyError as e: - print(e) - return responses.bad_request_400() - except Exception as e: - print(e) - return responses.internal_server_error_500() + db = ENV.database + updated_result = db.users.find_one_and_update( + { + "_id": sub, + }, + {"$set": user_data.get_existing_fields()}, + return_document=ReturnDocument.AFTER, + ) + print("Updated result:", updated_result) + if updated_result: + updated_result + else: + raise responses.internal_server_error_500() diff --git a/api/code/metroplanner_api/v1/endpoints/plans.py b/api/code/metroplanner_api/v1/endpoints/plans.py index a4b4a8a..a0435cb 100644 --- a/api/code/metroplanner_api/v1/endpoints/plans.py +++ b/api/code/metroplanner_api/v1/endpoints/plans.py @@ -13,86 +13,80 @@ @router.get("/{shortlink}") def get_plans(shortlink, request: Request) -> type_definitions.RetrievePlan: print(f"GET Request for plan for shortlink {shortlink}") - try: - db = ENV.database - link_result = db.links.find_one({"_id": shortlink}) - print("Link result:", link_result) - if link_result: - if link_result["active"]: - print("Link is active") - plan_id = link_result["plan"] - print("Plan ID is:", plan_id) - plan_result = db.plans.find_one( - {"_id": plan_id}, - ) - print("Plan result:", plan_result) - if plan_result: - if plan_result.get("deleted", None): - print( - f"Error: Plan with ID {plan_id} for " - f"Shortlink {shortlink} has been deleted." - ) - return responses.gone_410() - else: - print("Plan found and not deleted, getting stats") - stats_result = ( - db.stats.find_one( - { - "_id": { - "plan": ObjectId(plan_id), - "link": shortlink, - } - }, - { - "totalCount": 1, - "_id": 0, - }, - ) - or {} - ) - print("Stats found:", stats_result) - plan_result["totalViewCount"] = stats_result.get( - "totalCount", 0 - ) - for k, v in plan_result.items(): - if isinstance(v, ObjectId): - plan_result[k] = str(v) - plan_result.pop("deleted", None) - plan_result.pop("history", None) - plan_result.pop("_id", None) - plan_result: dict - return { - k: v - for k, v in plan_result.items() - if k - in [ - "planName", - "forkedFrom", - "ownedBy", - "createdAt", - "lastModifiedAt", - "likeCount", - "currentColorTheme", - "currentNumberOfEdges", - "currentNumberOfLabels", - "currentNumberOfLines", - "currentNumberOfNodes", - "totalViewCount", - "planDescription", - ] - } - else: + db = ENV.database + link_result = db.links.find_one({"_id": shortlink}) + print("Link result:", link_result) + if link_result: + if link_result["active"]: + print("Link is active") + plan_id = link_result["plan"] + print("Plan ID is:", plan_id) + plan_result = db.plans.find_one( + {"_id": plan_id}, + ) + print("Plan result:", plan_result) + if plan_result: + if plan_result.get("deleted", None): print( f"Error: Plan with ID {plan_id} for " - f"Shortlink {shortlink} does not exist." + f"Shortlink {shortlink} has been deleted." ) return responses.gone_410() + else: + print("Plan found and not deleted, getting stats") + stats_result = ( + db.stats.find_one( + { + "_id": { + "plan": ObjectId(plan_id), + "link": shortlink, + } + }, + { + "totalCount": 1, + "_id": 0, + }, + ) + or {} + ) + print("Stats found:", stats_result) + plan_result["totalViewCount"] = stats_result.get("totalCount", 0) + for k, v in plan_result.items(): + if isinstance(v, ObjectId): + plan_result[k] = str(v) + plan_result.pop("deleted", None) + plan_result.pop("history", None) + plan_result.pop("_id", None) + plan_result: dict + return { + k: v + for k, v in plan_result.items() + if k + in [ + "planName", + "forkedFrom", + "ownedBy", + "createdAt", + "lastModifiedAt", + "likeCount", + "currentColorTheme", + "currentNumberOfEdges", + "currentNumberOfLabels", + "currentNumberOfLines", + "currentNumberOfNodes", + "totalViewCount", + "planDescription", + ] + } else: - print("Link is inactive") - return responses.gone_410() + print( + f"Error: Plan with ID {plan_id} for " + f"Shortlink {shortlink} does not exist." + ) + raise responses.gone_410() else: - print("Link not found") - return responses.gone_410() - except Exception as e: - print("Exception!!:", e) - return responses.internal_server_error_500() + print("Link is inactive") + raise responses.gone_410() + else: + print("Link not found") + raise responses.gone_410() diff --git a/api/code/metroplanner_api/v1/endpoints/planstates.py b/api/code/metroplanner_api/v1/endpoints/planstates.py index f8e9faf..6aff7b5 100644 --- a/api/code/metroplanner_api/v1/endpoints/planstates.py +++ b/api/code/metroplanner_api/v1/endpoints/planstates.py @@ -14,67 +14,63 @@ def get_planstates(shortlink) -> type_definitions.Planstate: print(f"GET Request for planstate for shortlink {shortlink}") - try: - db = ENV.database - link_result = db.links.find_one({"_id": shortlink}) - print("Link result:", link_result) - if link_result: - if link_result["active"]: - print("Link is active") - plan_id = link_result["plan"] - print("Plan ID is:", plan_id) - plan_result = db.plans.find_one( - {"_id": plan_id}, {"currentState": 1, "deleted": 1} - ) - print("Plan result:", plan_result) - if plan_result: - if plan_result.get("deleted", None): - print( - f"Error: Plan with ID {plan_id} for " - f"Shortlink {shortlink} has been deleted." - ) - return responses.gone_410() - else: - print("Plan found and not deleted, getting latest state") - latest_state = db.planstates.find_one( - {"_id": plan_result["currentState"]}, {"_id": 0} - ) - print("Found latest state:", latest_state) - # latest_state["colorTheme"] = str(latest_state["colorTheme"]) + db = ENV.database + link_result = db.links.find_one({"_id": shortlink}) + print("Link result:", link_result) + if link_result: + if link_result["active"]: + print("Link is active") + plan_id = link_result["plan"] + print("Plan ID is:", plan_id) + plan_result = db.plans.find_one( + {"_id": plan_id}, {"currentState": 1, "deleted": 1} + ) + print("Plan result:", plan_result) + if plan_result: + if plan_result.get("deleted", None): + print( + f"Error: Plan with ID {plan_id} for " + f"Shortlink {shortlink} has been deleted." + ) + raise responses.gone_410() + else: + print("Plan found and not deleted, getting latest state") + latest_state = db.planstates.find_one( + {"_id": plan_result["currentState"]}, {"_id": 0} + ) + print("Found latest state:", latest_state) + # latest_state["colorTheme"] = str(latest_state["colorTheme"]) - time_to_hour = datetime.now().isoformat().split(":")[0] + time_to_hour = datetime.now().isoformat().split(":")[0] - try: - print("Updating stats") - update_stats_result = db.stats.update_one( - { - "_id": { - "plan": plan_id, - "link": shortlink, - } - }, - { - "$inc": { - "totalCount": 1, - f"views.{time_to_hour}": 1, - } - }, - upsert=True, - ) - print(update_stats_result) - except Exception as e: - print("Error updating statistics:", e) + try: + print("Updating stats") + update_stats_result = db.stats.update_one( + { + "_id": { + "plan": plan_id, + "link": shortlink, + } + }, + { + "$inc": { + "totalCount": 1, + f"views.{time_to_hour}": 1, + } + }, + upsert=True, + ) + print(update_stats_result) + except Exception as e: + print("Error updating statistics:", e) - return latest_state - else: - print(f"Plan with ID {plan_id} not found") - return responses.gone_410() + return latest_state else: - print("Link is not active") - return responses.gone_410() + print(f"Plan with ID {plan_id} not found") + raise responses.gone_410() else: - print(f"Link {shortlink} not found") - return responses.gone_410() - except Exception as e: - print("Exception!!:", e) - return responses.internal_server_error_500() + print("Link is not active") + raise responses.gone_410() + else: + print(f"Link {shortlink} not found") + raise responses.gone_410() diff --git a/api/code/metroplanner_api/v1/endpoints/users.py b/api/code/metroplanner_api/v1/endpoints/users.py index d268898..e4df240 100644 --- a/api/code/metroplanner_api/v1/endpoints/users.py +++ b/api/code/metroplanner_api/v1/endpoints/users.py @@ -25,7 +25,7 @@ def get_user(user_id) -> type_definitions.User: # TODO collect plans created # TODO collect plans liked print("User Profile is public") - return responses.ok(user_data) + return user_data else: print("User Profile is not public") raise responses.forbidden_403()