This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
164 lines (104 loc) · 4.09 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import api_handler as ah
import api_handler.category
import api_handler.goods
import api_handler.order
from flask import Flask, request
app = Flask(__name__)
api_ver = 'v1'
def api(location):
return '/'.join(('', api_ver, location))
# Category
@app.route(api('category/all'), methods=['GET'])
def category_all():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.category.all(limit=limit)
@app.route(api('category/<int:cat_id>'), methods=['GET'])
def category_one(cat_id):
return ah.category.one(id=cat_id)
@app.route(api('category/add'), methods=['POST'])
def category_add():
return ah.category.add(info=request.json)
@app.route(api('category/<int:cat_id>/update'), methods=['POST'])
def category_update(cat_id):
return ah.category.update(id=cat_id, info=request.json)
@app.route(api('category/<int:cat_id>/delete'), methods=['POST'])
def category_delete(cat_id):
return ah.category.delete(id=cat_id)
# Goods
@app.route(api('goods/all'), methods=['GET'])
def goods_all():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.goods.all(limit=limit)
@app.route(api('goods/<int:goods_id>'), methods=['GET'])
def goods_one(goods_id):
return ah.goods.one(id=goods_id)
@app.route(api('goods/add'), methods=['POST'])
def goods_add():
return ah.goods.add(info=request.json)
@app.route(api('goods/<int:goods_id>/update'), methods=['POST'])
def goods_update(goods_id):
return ah.goods.update(id=goods_id, info=request.json)
@app.route(api('goods/<int:goods_id>/delete'), methods=['POST'])
def goods_delete(goods_id):
return ah.goods.delete(id=goods_id)
# Order
@app.route(api('order/all'), methods=['GET'])
def order_all():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.order.all(limit=limit)
@app.route(api('order/unhandled'), methods=['GET'])
def order_unhandled():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.order.unhandled(limit=limit)
@app.route(api('order/uncompleted'), methods=['GET'])
def order_uncompleted():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.order.uncompleted(limit=limit)
@app.route(api('order/completed'), methods=['GET'])
def order_completed():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.order.completed(limit=limit)
@app.route(api('order/closed'), methods=['GET'])
def order_closed():
limit = request.args.get('limit')
limit = int(limit) if limit else limit
return ah.order.closed(limit=limit)
@app.route(api('order/<int:order_id>'), methods=['GET'])
def order_one(order_id):
return ah.order.one(id=order_id)
@app.route(api('order/add'), methods=['POST'])
def order_add():
return ah.order.add(info=request.json)
@app.route(api('order/<int:order_id>/update'), methods=['POST'])
def order_update(order_id):
return ah.order.update(id=order_id, info=request.json)
@app.route(api('order/<int:order_id>/handle'), methods=['POST'])
def order_handle(order_id):
return ah.order.handle(id=order_id)
@app.route(api('order/<int:order_id>/complete'), methods=['POST'])
def order_complete(order_id):
return ah.order.complete(id=order_id)
@app.route(api('order/<int:order_id>/close'), methods=['POST'])
def order_close(order_id):
return ah.order.close(id=order_id)
@app.route(api('order/<int:order_id>/delete'), methods=['POST'])
def order_delete(order_id):
return ah.order.delete(id=order_id)
@app.route(api('order/<int:order_id>/rate'), methods=['POST'])
def order_rate(order_id):
score = request.args.get('score')
score = int(score) if score else score
return ah.order.rate(id=order_id, score=score)
@app.route(api('order/sold-goods/<int:sold_goods_id>/rate'), methods=['POST'])
def order_rate_sold_goods(sold_goods_id):
score = request.args.get('score')
score = int(score) if score else score
return ah.order.rate_sold_goods(id=sold_goods_id, score=score)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=8000)