-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
79 lines (65 loc) · 2.31 KB
/
Copy pathserver.py
File metadata and controls
79 lines (65 loc) · 2.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from flask import Flask, request, jsonify, send_from_directory
from sql_connection import get_sql_connection
import mysql.connector
import json
import products_dao
import orders_dao
import uom_dao
app = Flask(__name__,static_folder='.', static_url_path='')
connection = get_sql_connection()
@app.route('/')
def index():
return send_from_directory('.', 'index.html')
@app.route('/manage-product')
def manage_product():
return send_from_directory('.', 'manage-product.html')
@app.route('/order')
def order():
return send_from_directory('.', 'order.html')
@app.route('/getUOM', methods=['GET'])
def get_uom():
response = uom_dao.get_uoms(connection)
response = jsonify(response)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/getProducts', methods=['GET'])
def get_products():
response = products_dao.get_all_products(connection)
response = jsonify(response)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/insertProduct', methods=['POST'])
def insert_product():
request_payload = json.loads(request.form['data'])
product_id = products_dao.insert_new_product(connection, request_payload)
response = jsonify({
'product_id': product_id
})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/getAllOrders', methods=['GET'])
def get_all_orders():
response = orders_dao.get_all_orders(connection)
response = jsonify(response)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/insertOrder', methods=['POST'])
def insert_order():
request_payload = json.loads(request.form['data'])
order_id = orders_dao.insert_order(connection, request_payload)
response = jsonify({
'order_id': order_id
})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/deleteProduct', methods=['POST'])
def delete_product():
return_id = products_dao.delete_product(connection, request.form['product_id'])
response = jsonify({
'product_id': return_id
})
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)