diff --git a/main.py b/main.py index 432779b..003c12f 100644 --- a/main.py +++ b/main.py @@ -125,32 +125,32 @@ def address_search(): @main.route('/plan_search') def plan_search(): - plan_req: List[str] = request.args.get('plans', '').split(',') - if not plan_req or plan_req == ['']: + plan_req: Dict[str] = request.args.to_dict(flat=False) + if not plan_req or "plans" not in plan_req: return jsonify({"plans": []}), HTTPStatus.OK - - try: - plans = ( - db.session.query(Plans) - .filter(Plans.PlanIdentifier.in_(plan_req)) - .all() - ) - - plan_list = [ - { - "plan": plan.PlanIdentifier, - "planName": plan.Name, - "cost": plan.Cost, - "description": plan.Description, - "uploadSpeed": plan.UploadSpeed, - "downloadSpeed": plan.DownloadSpeed, - "wholesale": False - } - for plan in plans - ] - - return jsonify({"plans": plan_list}), HTTPStatus.OK - - except Exception as e: - db.session.rollback() - raise APIError(f"Error searching plans: {str(e)}", HTTPStatus.INTERNAL_SERVER_ERROR) \ No newline at end of file + else: + try: + plans = ( + db.session.query(Plans) + .filter(Plans.PlanIdentifier.in_(plan_req['plans'])) + .all() + ) + + plan_list = [ + { + "plan": plan.PlanIdentifier, + "planName": plan.Name, + "cost": plan.Cost, + "description": plan.Description, + "uploadSpeed": plan.UploadSpeed, + "downloadSpeed": plan.DownloadSpeed, + "wholesale": False + } + for plan in plans + ] + + return jsonify({"plans": plan_list}), HTTPStatus.OK + + except Exception as e: + db.session.rollback() + raise APIError(f"Error searching plans: {str(e)}", HTTPStatus.INTERNAL_SERVER_ERROR) \ No newline at end of file