Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Blueprint, jsonify, request, json, session
from models.updateProduct import update_product_info
from publishers.kafkaPublishers import publish_product_updated_event
import requests
update_product_bp = Blueprint("updateProduct",__name__)
@update_product_bp.route("/product/updateProduct", methods=["POST"])
def update_product():
user_id = session.get("user_id")
if user_id:
if request.method == 'POST':
data = request.get_json()
price = data.get("price")
quantity = data.get("quantity")
product_id = data.get("product_id")
#username = session.get('username')
if isinstance(data.get("price"), (int, float)):
if isinstance(data.get("quantity"), int):
info = {
"quantity" : quantity,
"price" : price,
"product_id" : product_id
}
update = update_product_info(info)
if "message" in update:
event_data = {"quantity" : quantity, "price" : price, "product_id" : product_id}
publish_product_updated_event(event_data)
return {"Update Status": update}
else:
return {"error" : "error"}
else:
return {"error" : "Quantity should be int"}
else:
return{"error" : "Price should be a number"}
else:
return {"error" : "null"}
else:
return {"error" : "You need to be logged in to add a review"}