Skip to content

Commit

Permalink
refactor: fga-eps-mds/2020.2-Lend.it#138 Refactored get requests filt…
Browse files Browse the repository at this point in the history
…ered by category route

Co-authored-by: Thiago Mesquita <thiago099carvalho@gmail.com>
Co-authored-by: Mateus Maia <mateusmaiamaia@hotmail.com>
  • Loading branch information
3 people committed Apr 24, 2021
1 parent 1e028ac commit d2f1ce8
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions project/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
request_blueprint = Blueprint("requests", __name__)


def convert_enddate(enddate):
parsed_date = date.fromisoformat(enddate)
return parsed_date


@category_blueprint.route("/product_category", methods=["GET"])
def get_all_categories():
response = {
Expand Down Expand Up @@ -62,6 +57,7 @@ def add_categories():
def get_all_request():
requester = request.args.get("requester")
lender = request.args.get("lender")

if requester:
requests = get_category_name(
[
Expand Down Expand Up @@ -124,17 +120,31 @@ def get_all_available_requests():
return jsonify(response), 200


@request_blueprint.route("/requests/<productcategoryid>", methods=["GET"])
def get_filtered_request(productcategoryid):
@request_blueprint.route("/requests/available/<productcategoryid>", methods=["GET"])
def get_requests_filtered_by_category(productcategoryid):
usermail = request.args.get("usermail")

today_date = datetime.now()
today_date = today_date.replace(hour=0, minute=0, second=0, microsecond=0)
today_date.isoformat()

error_response = {"status": "fail", "message": "Request not found"}

requests = get_category_name(
[
request.to_json()
for request in Request.query.filter_by(
productcategoryid=productcategoryid
for request in Request.query.filter(
Request.lender == None,
Request.requester != usermail,
Request.enddate >= today_date,
Request.productcategoryid == productcategoryid,
).all()
]
)

if not requests:
return jsonify(error_response), 404

response = {
"status": "success",
"data": {"requests": requests},
Expand Down

0 comments on commit d2f1ce8

Please # to comment.