From 07c8462ca7c4f8cc945e78cf04e50b56c4e7a1f9 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 16 Apr 2021 20:28:29 -0300 Subject: [PATCH 1/3] feat: fga-eps-mds/2020.2-Lend.it#133 Created route to get available requests --- project/api/views.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/project/api/views.py b/project/api/views.py index c0915be..75798c1 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -90,6 +90,27 @@ def get_all_request(): return jsonify(response), 200 +@request_blueprint.route("/requests/", methods=["GET"]) +def get_all_available_requests(usermail): + error_response = {"status": "fail", "message": "Request not found"} + + available_requests = [ + request.to_json() + for request in Request.query.filter( + Request.lender == None, Request.requester != usermail + ).all() + ] + + if not available_requests: + return jsonify(error_response), 404 + + response = { + "status": "success", + "data": {"available requests": available_requests}, + } + return jsonify(response), 200 + + @request_blueprint.route("/requests/", methods=["GET"]) def get_filtered_request(productcategoryid): requests = get_category_name( From b61c6bc13e9dc2befb26068145335f3685335cf1 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 16 Apr 2021 23:45:17 -0300 Subject: [PATCH 2/3] feat: fga-eps-mds/2020.2-Lend.it#133 Created route to get available requests --- project/api/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 75798c1..5468865 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -90,7 +90,7 @@ def get_all_request(): return jsonify(response), 200 -@request_blueprint.route("/requests/", methods=["GET"]) +@request_blueprint.route("/requests/available/", methods=["GET"]) def get_all_available_requests(usermail): error_response = {"status": "fail", "message": "Request not found"} @@ -106,7 +106,7 @@ def get_all_available_requests(usermail): response = { "status": "success", - "data": {"available requests": available_requests}, + "data": {"available_requests": available_requests}, } return jsonify(response), 200 From 0ba7d9e25f33fe601fd94f8f72310fedb865596e Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Sat, 17 Apr 2021 17:20:18 -0300 Subject: [PATCH 3/3] feat: fga-eps-mds/2020.2-Lend.it#133 Changed route apperance --- project/api/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 5468865..b6481f4 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -90,8 +90,10 @@ def get_all_request(): return jsonify(response), 200 -@request_blueprint.route("/requests/available/", methods=["GET"]) -def get_all_available_requests(usermail): +@request_blueprint.route("/requests/available", methods=["GET"]) +def get_all_available_requests(): + usermail = request.args.get("usermail") + error_response = {"status": "fail", "message": "Request not found"} available_requests = [ @@ -106,7 +108,7 @@ def get_all_available_requests(usermail): response = { "status": "success", - "data": {"available_requests": available_requests}, + "data": {"available requests": get_category_name(available_requests)}, } return jsonify(response), 200