Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
17ead1f
feat: fga-eps-mds/2020.2-Lend.it#109 Create delete method for product…
Thais-ra Mar 24, 2021
bf9fecb
refactor: fga-eps-mds/2020.2-Lend.it#109 Fix delete request
mateusmaiamaia Mar 25, 2021
dcd190d
Merge branch 'devel' of https://github.com/Lend-it/Request into 109_d…
Thais-ra Mar 27, 2021
6d7efd6
chore: fga-eps-mds/2020.2-Lend.it#109 Change caused by lint
Thais-ra Mar 27, 2021
ae48c3c
Merge branch 'devel' of https://github.com/Lend-it/Request into 109_d…
mateusmaiamaia Mar 27, 2021
1f275e5
Merge branch '109_deletar_lend' of https://github.com/Lend-it/Request…
mateusmaiamaia Mar 27, 2021
fc130a2
feat: fga-eps-mds/2020.2-Lend.it#121 create update lender method
mateusmaiamaia Mar 31, 2021
bd32946
feat: fga-eps-mds/2020.2-Lend.it#121 create test for update lend request
mateusmaiamaia Mar 31, 2021
d273e8d
chore: fga-eps-mds/2020.2-Lend.it#121 remove duplicated import db
Matheusafonsouza Apr 1, 2021
f4313a8
chore: fga-eps-mds/2020.2-Lend.it#121 remove try catch and create tes…
Matheusafonsouza Apr 1, 2021
ba2892b
Merge branch 'devel' of github.com:Lend-it/Request into 121_ajudar_so…
Matheusafonsouza Apr 1, 2021
51757c3
Merge branch 'devel' of github.com:Lend-it/Request into 121_ajudar_so…
Matheusafonsouza Apr 1, 2021
4d572a8
Merge branch '121_ajudar_solicitação' of github.com:Lend-it/Request i…
Matheusafonsouza Apr 1, 2021
0354cdf
feat: fga-eps-mds/2020.2-Lend.it#121 create function for category join
mateusmaiamaia Apr 2, 2021
bbdcade
ci: fga-eps-mds/2020.2-Lend.it#121 Remove temporarily linter step
lucasdutraf Apr 2, 2021
0a4b9b2
refactor: fga-eps-mds/2020.2-Lend.it#121 Update html cov script in Ma…
lucasdutraf Apr 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/black.yml

This file was deleted.

8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
sudo docker-compose -f docker-compose.dev.yml run request python manage.py cov;
google-chrome $(CURRENT_DIR)/htmlcov/index.html;
10 changes: 10 additions & 0 deletions project/api/utils.py
Original file line number Diff line number Diff line change
@@ -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
25 changes: 24 additions & 1 deletion project/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -102,6 +104,27 @@ def create_request():
return jsonify(error_response), 400


@request_blueprint.route("/requests/<requestid>", methods=["PATCH"])
def update_request_lender(requestid):
post_data = request.get_json()

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

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", "request": product.to_json()}

return jsonify(response), 200


@request_blueprint.route("/requests/<requestid>", methods=["PUT"])
def edit_request(requestid):

Expand Down
31 changes: 31 additions & 0 deletions project/tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,34 @@ 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"])

def test_cannot_update_non_existing_request_lender(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)