From 2cd89d6b108de0f7a6a7d6c7269b47461d18e83c Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Thu, 1 Apr 2021 13:42:14 -0300 Subject: [PATCH 1/4] refactor: Changed function name --- project/api/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 418d3b9..a62e2ab 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -12,7 +12,7 @@ @category_blueprint.route("/product_category", methods=["GET"]) -def get_all_request(): +def get_all_categories(): response = { "status": "success", "data": { @@ -47,8 +47,7 @@ def add_categories(): response = { "status": "fail", "data": { - "status": "Category not created", - "error_msg": err.to_json(), + "status": "Could not create Category", }, } db.session.rollback() @@ -164,8 +163,7 @@ def edit_request(requestid): response = { "status": "fail", "data": { - "update_status": "Update not complete!", - "error_msg": err.to_json(), + "update_status": "Could not update Request", }, } db.session.rollback() @@ -186,7 +184,7 @@ def delete_request(requestid): response = {"status": "success", "data": {"message": "Request deleted!"}} - return jsonify(response), 202 + return jsonify(response), 200 except exc.IntegrityError as e: db.session.rollback() return jsonify(error_response), 400 From 7b622e9a59d8aaab632f40894c66a70503832dbf Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Thu, 1 Apr 2021 13:42:14 -0300 Subject: [PATCH 2/4] refactor: Update status codes --- project/api/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/project/api/views.py b/project/api/views.py index a62e2ab..6d7dd75 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -163,7 +163,12 @@ def edit_request(requestid): response = { "status": "fail", "data": { +<<<<<<< HEAD "update_status": "Could not update Request", +======= + "update_status": "Update not complete!", + "error_msg": str(err), +>>>>>>> Changed function name }, } db.session.rollback() @@ -177,7 +182,7 @@ def delete_request(requestid): error_response = {"status": "fail", "message": "Could not delete request."} if not request: - return jsonify(error_response), 404 + return jsonify(error_response), 400 try: db.session.delete(request) db.session.commit() From e62d6fe6fc0cc3dcc608b3633ab47fa6647faf32 Mon Sep 17 00:00:00 2001 From: Lucas Dutra Date: Fri, 2 Apr 2021 21:19:22 -0300 Subject: [PATCH 3/4] refactor: Update not found status code --- project/api/views.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 6d7dd75..e1eb08a 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -131,7 +131,7 @@ def edit_request(requestid): error_response = {"status": "fail", "message": "Invalid payload."} if not put_data: - return jsonify(error_response), 400 + return jsonify(error_response), 404 request_obj = Request.query.filter_by(requestid=requestid).first() @@ -163,12 +163,7 @@ def edit_request(requestid): response = { "status": "fail", "data": { -<<<<<<< HEAD "update_status": "Could not update Request", -======= - "update_status": "Update not complete!", - "error_msg": str(err), ->>>>>>> Changed function name }, } db.session.rollback() From d222d760aed936b6aaf504b4c999d0484ddd88e7 Mon Sep 17 00:00:00 2001 From: Lucas Dutra Date: Fri, 2 Apr 2021 21:28:28 -0300 Subject: [PATCH 4/4] refactor: Remove unused variables --- project/api/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index e1eb08a..8389c1f 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -43,7 +43,7 @@ def add_categories(): } return jsonify(response), 201 - except Exception as err: + except exc.IntegrityError: response = { "status": "fail", "data": { @@ -159,7 +159,7 @@ def edit_request(requestid): } return jsonify(response), 201 - except Exception as err: + except exc.IntegrityError: response = { "status": "fail", "data": { @@ -177,7 +177,7 @@ def delete_request(requestid): error_response = {"status": "fail", "message": "Could not delete request."} if not request: - return jsonify(error_response), 400 + return jsonify(error_response), 404 try: db.session.delete(request) db.session.commit()