-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathserver.py
More file actions
50 lines (40 loc) · 1.45 KB
/
server.py
File metadata and controls
50 lines (40 loc) · 1.45 KB
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
from flask import Flask, request, jsonify
from sql_connection import get_sql_connection
import mysql.connector
import json
import products_dao
import orders_dao
import uom_dao
app = Flask(__name__)
connection = get_sql_connection()
# Passes ID and Edits details of a product
@app.route('/editProduct', methods=['POST', 'GET'])
def edit_product():
request_payload = json.loads(request.form['data'])
product_id = products_dao.edit_product(connection, request_payload)
response = jsonify({
'product_id': product_id
})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
# Inserts new UOM
@app.route('/insertUOM', methods=['GET', 'POST'])
def insert_uom():
request_payload = json.loads(request.form['data'])
uom_id = uom_dao.insert_new_uom(connection,request_payload)
response = jsonify({
'uom_id': uom_id
})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
# Order details (customer_name, product, quantity, total_price)
# of a particular order is fetched from the Database
@app.route('/getOrderDetails', methods=['GET'])
def get_order_details():
response = orders_dao.get_order_details(connection, request.form['order_id'])
response = jsonify(response)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
if __name__ == "__main__":
print("Starting Python Flask Server For Grocery Store Management System")
app.run(port=5000)