-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_api.py
66 lines (49 loc) · 1.75 KB
/
my_api.py
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
from flask import Flask,request,jsonify
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast
import json
from order import OrderParser
from requestrespone import *
from BillOptimizer import *
from flask import Flask, jsonify
from OpenSSL import SSL
app = Flask(__name__)
api = Api(app)
class Users(Resource):
# methods go here
def get(self):
data = pd.read_csv('users.csv') # read CSV
data = data.to_dict() # convert dataframe to dictionary
return {'data': data}, 200 # return data and 200 OK code
def post(self):
#form=request.form
data=request.get_json()
print(data)
return {'data': "abc"}, 200 # return data with 200 OK
pass
class Locations(Resource):
def post(self):
#form=request.form
data=request.get_json()
print(data)
return {'data': "abc"}, 200 # return data with 200 OK
pass
class Dishes(Resource):
def post(self):
jsonstring=request.get_json()
print("request json")
print(jsonstring)
billObject:BillRequestObject = BillRequest(jsonstring).getObject()
opimizer=BillOptimizer(billObject.shipping_fee,billObject.orders,billObject.vouchers)
result=opimizer.optimize()
print(result)
# json_data=json.dumps(result,default=lambda o: o.__dict__)
jsonObject=json.loads(result)
return jsonObject,200
pass
api.add_resource(Dishes, '/dishes') # '/users' is our entry point for Users
api.add_resource(Users, '/users') # '/users' is our entry point for Users
api.add_resource(Locations, '/locations') # and '/locations' is our entry point for Locations
if __name__ == '__main__':
app.run(host='0.0.0.0') # run our Flask app