-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast_rest.py
66 lines (47 loc) · 1.55 KB
/
fast_rest.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, jsonify,request
from flask_restful import Resource, Api
from pymongo import MongoClient
from bson.json_util import dumps
app = Flask(__name__)
api = Api(app)
c = MongoClient()
db=c.food
m=db.count.insert_one({"count":1})
@app.route('/getorder', methods=['GET'])
def get_orders():
cursor=db.orders.find()
#cursor=str(cursor)
return dumps(cursor)
@app.route('/getorder/<int:orderid>',methods=['GET'])
def get_order(orderid):
cursor=db.orders.find_one({"order_id":orderid})
return dumps(cursor)
@app.route('/saveorder',methods=['POST'])
def save_order():
cursor=db.count.find_one()
count=cursor['count']
count=int(count)
count+=1
db.orders.insert_one({
'order_id':count,
'cust_address':request.json['cust_address'],
'cust_contact':request.json['cust_contact'],
'cust_name':request.json['cust_name'],
'cust_pincode':request.json['cust_pincode'],
'order_description':request.json['order_description']
})
temp=count-1;
re=db.count.update_one({"count":temp},{"$set":{"count":count}})
return dumps(db.orders.find_one({"order_id":count}))
@app.route('/saveorder/<int:orderid>',methods = ['POST'])
def update_order(orderid):
db.orders.update_one({"order_id":orderid},{"$set":{
'cust_address':request.json['cust_address'],
'cust_contact':request.json['cust_contact'],
'cust_name':request.json['cust_name'],
'cust_pincode':request.json['cust_pincode'],
'order_description':request.json['order_description']
}})
return dumps(db.orders.find_one({"order_id":orderid}))
if __name__ == '__main__':
app.run(debug=True)