|
|
|
@ -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) |
|
|
|
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) |