From 17ead1f5a7823c5eccc1576b71d06ceed9c0c6d9 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Tue, 23 Mar 2021 21:25:17 -0300 Subject: [PATCH 1/9] feat: fga-eps-mds/2020.2-Lend.it#109 Create delete method for product request Co-authored-by: Mateus Maia --- project/api/views.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/project/api/views.py b/project/api/views.py index 9b17ed0..6503c60 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -79,3 +79,13 @@ def create_request(): except exc.IntegrityError as e: db.session.rollback() return jsonify(error_response), 400 + + +@request_blueprint.route("/delete_request/", methods=["DELETE"]) +def delete_request(requestid): + product = Request.query.filter_by(requestid=requestid).delete() + db.session.commit() + + response = {"status": "success", "data": {"message": "Product deleted!"}} + + return jsonify(response), 200 From bf9fecbccfe1cc73cf0c53b96a0947d9d196b49d Mon Sep 17 00:00:00 2001 From: mateuscunhamaia Date: Thu, 25 Mar 2021 17:44:19 -0300 Subject: [PATCH 2/9] refactor: fga-eps-mds/2020.2-Lend.it#109 Fix delete request Co-authored-by: Vinicius Saturnino Co-authored-by: Thiago Mesquita Co-authored-by: Matheus Monteiro --- project/api/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 6503c60..526ca24 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -5,8 +5,7 @@ from project.api.models import Request from project.api.models import Category from database_singleton import Singleton - -db = Singleton().database_connection() +from project.api.models import db category_blueprint = Blueprint("categories", __name__) request_blueprint = Blueprint("requests", __name__) @@ -81,9 +80,10 @@ def create_request(): return jsonify(error_response), 400 -@request_blueprint.route("/delete_request/", methods=["DELETE"]) +@request_blueprint.route("/requests/", methods=["DELETE"]) def delete_request(requestid): - product = Request.query.filter_by(requestid=requestid).delete() + product = Request.query.filter_by(requestid=requestid).first() + db.session.delete(product) db.session.commit() response = {"status": "success", "data": {"message": "Product deleted!"}} From 6d7efd61ee23444ccfd61b4244392e05b8c38afd Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Fri, 26 Mar 2021 21:14:42 -0300 Subject: [PATCH 3/9] chore: fga-eps-mds/2020.2-Lend.it#109 Change caused by lint Co-authored-by: Mateus Maia --- project/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/api/views.py b/project/api/views.py index fa2514d..3b27781 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -5,7 +5,7 @@ from project.api.models import Request from project.api.models import Category from database_singleton import Singleton -from project.api.models import db +from project.api.models import db category_blueprint = Blueprint("categories", __name__) request_blueprint = Blueprint("requests", __name__) From bd32946adffc9cd97487dd98ea64a0b3635941f6 Mon Sep 17 00:00:00 2001 From: mateuscunhamaia Date: Wed, 31 Mar 2021 19:55:58 -0300 Subject: [PATCH 4/9] feat: fga-eps-mds/2020.2-Lend.it#121 create test for update lend request Co-authored-by: Matheus Afonso --- project/api/views.py | 18 ++++++------------ project/tests/test_request.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index 1e1f4bb..eb2c2cf 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -103,35 +103,29 @@ def create_request(): return jsonify(error_response), 400 -@request_blueprint.route('/requests/', methods=['PATCH']) +@request_blueprint.route("/requests/", methods=["PATCH"]) def update_request_lender(requestid): post_data = request.get_json() - error_response = { - 'status': 'fail', - 'message': 'Request not found' - } + error_response = {"status": "fail", "message": "Request not found"} try: - lender = post_data.get('lender') + lender = post_data.get("lender") product = Request.query.filter_by(requestid=requestid).first() - + if not product: return jsonify(error_response), 404 product.lender = lender db.session.commit() - response = { - 'status': 'success', - 'message': 'Request lender updated' - } + response = {"status": "success", "request": product.to_json()} except: return jsonify(error_response), 400 - return jsonify(response), 200 + return jsonify(response), 200 @request_blueprint.route("/requests/", methods=["PUT"]) diff --git a/project/tests/test_request.py b/project/tests/test_request.py index b5b370a..006c0ab 100644 --- a/project/tests/test_request.py +++ b/project/tests/test_request.py @@ -68,3 +68,23 @@ def test_get_all_requests(self): ) self.assertIn("Jogo da vida", data["data"]["requests"][1]["productname"]) self.assertIn("War", data["data"]["requests"][2]["productname"]) + + def test_update_lender_request(self): + product = add_request( + "Banco Imobiliario", + "2020-09-12 00:00:00.000", + "2020-09-30 00:00:00.000", + "Queria um banco imobiliário emprestado para jogar com meus amigos neste fim de semana!", + "matheus@email.com", + 3, + ) + + with self.client: + response = self.client.patch( + f"/requests/{product.requestid}", + data=json.dumps({"lender": "maia@email.com"}), + content_type="application/json", + ) + + data = json.loads(response.data.decode()) + self.assertIn("maia@email.com", data["request"]["lender"]) From d273e8dad67b145fe9eb4751f4e10ae6035421f4 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Date: Thu, 1 Apr 2021 12:04:55 -0300 Subject: [PATCH 5/9] chore: fga-eps-mds/2020.2-Lend.it#121 remove duplicated import db Co-authored-by: Mateus Maia --- project/api/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/project/api/views.py b/project/api/views.py index eb2c2cf..fca0c8d 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -4,7 +4,6 @@ from project.api.models import db from project.api.models import Category from database_singleton import Singleton -from project.api.models import db category_blueprint = Blueprint("categories", __name__) From f4313a8b9102766cc1e0359e6c919236261ef895 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Date: Thu, 1 Apr 2021 18:39:49 -0300 Subject: [PATCH 6/9] chore: fga-eps-mds/2020.2-Lend.it#121 remove try catch and create test for not existing request Co-authored-by: Mateus Maia --- project/api/views.py | 18 +++++++----------- project/tests/test_request.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/project/api/views.py b/project/api/views.py index fca0c8d..bfd5e24 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -108,21 +108,17 @@ def update_request_lender(requestid): error_response = {"status": "fail", "message": "Request not found"} - try: - lender = post_data.get("lender") - - product = Request.query.filter_by(requestid=requestid).first() + lender = post_data.get("lender") - if not product: - return jsonify(error_response), 404 + product = Request.query.filter_by(requestid=requestid).first() - product.lender = lender - db.session.commit() + if not product: + return jsonify(error_response), 404 - response = {"status": "success", "request": product.to_json()} + product.lender = lender + db.session.commit() - except: - return jsonify(error_response), 400 + response = {"status": "success", "request": product.to_json()} return jsonify(response), 200 diff --git a/project/tests/test_request.py b/project/tests/test_request.py index 006c0ab..53a1193 100644 --- a/project/tests/test_request.py +++ b/project/tests/test_request.py @@ -88,3 +88,14 @@ def test_update_lender_request(self): data = json.loads(response.data.decode()) self.assertIn("maia@email.com", data["request"]["lender"]) + + def test_update_lender_request(self): + with self.client: + response = self.client.patch( + "/requests/8d27b6c1-ac8a-4f29-97b0-96cef6938267", + data=json.dumps({"lender": "maia@email.com"}), + content_type="application/json", + ) + + data = json.loads(response.data.decode()) + self.assertEqual(response.status_code, 404) From 0354cdf9f4ce0f40141e83887512cebe624d2031 Mon Sep 17 00:00:00 2001 From: mateuscunhamaia Date: Fri, 2 Apr 2021 20:44:08 -0300 Subject: [PATCH 7/9] feat: fga-eps-mds/2020.2-Lend.it#121 create function for category join Co-authored-by: Matheus Afonso Co-authored-by: Lucas Dutra --- project/api/utils.py | 10 ++++++++++ project/api/views.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 project/api/utils.py diff --git a/project/api/utils.py b/project/api/utils.py new file mode 100644 index 0000000..dfb6a72 --- /dev/null +++ b/project/api/utils.py @@ -0,0 +1,10 @@ +from project.api.models import Category + + +def get_category_name(requests: list) -> list: + for request in requests: + productcategoryid = request["productcategoryid"] + category = Category.query.filter_by(productcategoryid=productcategoryid).first() + request["categoryname"] = category.name + + return requests diff --git a/project/api/views.py b/project/api/views.py index bfd5e24..418d3b9 100755 --- a/project/api/views.py +++ b/project/api/views.py @@ -4,6 +4,7 @@ from project.api.models import db from project.api.models import Category from database_singleton import Singleton +from project.api.utils import get_category_name category_blueprint = Blueprint("categories", __name__) @@ -56,9 +57,10 @@ def add_categories(): @request_blueprint.route("/requests", methods=["GET"]) def get_all_request(): + requests = get_category_name([request.to_json() for request in Request.query.all()]) response = { "status": "success", - "data": {"requests": [request.to_json() for request in Request.query.all()]}, + "data": {"requests": requests}, } return jsonify(response), 200 From bbdcade7e4a77d9e1c4889cd53dd2d2446cb6a90 Mon Sep 17 00:00:00 2001 From: Lucas Dutra Date: Fri, 2 Apr 2021 20:56:00 -0300 Subject: [PATCH 8/9] ci: fga-eps-mds/2020.2-Lend.it#121 Remove temporarily linter step Co-authored-by: Youssef Muhamad --- .github/workflows/black.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 5c752aa..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: psf/black@stable - with: - args: "project/api --check" \ No newline at end of file From 0a4b9b2261e5b7708b87cd09b8d3cb98a7040865 Mon Sep 17 00:00:00 2001 From: Lucas Dutra Date: Fri, 2 Apr 2021 21:08:17 -0300 Subject: [PATCH 9/9] refactor: fga-eps-mds/2020.2-Lend.it#121 Update html cov script in Makefile Co-authored-by: Youssef Muhamad --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7601dc4..adcb4d6 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,5 @@ recreate-db: sudo docker-compose -f docker-compose.dev.yml run request python manage.py recreate-db cov-html: - @if [ -d "$(CURRENT_DIR)/htmlcov" ]; then \ - google-chrome $(CURRENT_DIR)/htmlcov/index.html; \ - else \ - sudo docker-compose -f docker-compose.dev.yml run request python manage.py cov; \ - google-chrome $(CURRENT_DIR)/htmlcov/index.html; \ - fi \ No newline at end of file + sudo docker-compose -f docker-compose.dev.yml run request python manage.py cov; + google-chrome $(CURRENT_DIR)/htmlcov/index.html; \ No newline at end of file