handle cors
This commit is contained in:
parent
5a83c3d4c7
commit
e25bb5594c
@ -46,7 +46,9 @@ def index(crud):
|
|||||||
cursor = db_main.cursor(dictionary=True)
|
cursor = db_main.cursor(dictionary=True)
|
||||||
|
|
||||||
payload = request.json
|
payload = request.json
|
||||||
if crud == "create":
|
if request.method == 'OPTIONS':
|
||||||
|
return None
|
||||||
|
elif crud == "create":
|
||||||
name = payload["name"]
|
name = payload["name"]
|
||||||
price = payload["price"]
|
price = payload["price"]
|
||||||
qty = payload["qty"]
|
qty = payload["qty"]
|
||||||
@ -57,15 +59,16 @@ def index(crud):
|
|||||||
return json.dumps(result, indent = 2).encode()
|
return json.dumps(result, indent = 2).encode()
|
||||||
|
|
||||||
data_id = cursor.execute("INSERT INTO `items` (name, price, qty) VALUES (%s, %s, %s);", (name, price, qty))
|
data_id = cursor.execute("INSERT INTO `items` (name, price, qty) VALUES (%s, %s, %s);", (name, price, qty))
|
||||||
|
db_main.commit()
|
||||||
|
|
||||||
|
# Get the newly created item with its ID
|
||||||
|
cursor.execute("SELECT * FROM `items` WHERE `id` = LAST_INSERT_ID();")
|
||||||
|
new_item = cursor.fetchone()
|
||||||
|
|
||||||
result["status"] = "success"
|
result["status"] = "success"
|
||||||
result["message"] = f'{payload["name"]} is added to the list.'
|
result["message"] = f'{payload["name"]} is added to the list.'
|
||||||
|
|
||||||
result["data"] = {
|
result["data"] = new_item
|
||||||
"name": name,
|
|
||||||
"price": price,
|
|
||||||
"qty": qty
|
|
||||||
}
|
|
||||||
|
|
||||||
elif crud == "read":
|
elif crud == "read":
|
||||||
cursor.execute("SELECT * FROM `items`;")
|
cursor.execute("SELECT * FROM `items`;")
|
||||||
|
Loading…
Reference in New Issue
Block a user