-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
73 lines (62 loc) · 1.96 KB
/
api.py
File metadata and controls
73 lines (62 loc) · 1.96 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
#!flask/bin/python
from flask import Flask, jsonify
from flask import abort
from flask import make_response
app = Flask(__name__)
products = [
{
'id': 1,
'name': u'Iphone',
'inventory': 100,
'revenue_dp': 80,
'costprice': 100,
'revenue_cp': 50,
'num_bids_item': 8,
'num_bids_total': 7,
'inventory': 5,
'max_inventory': 10
},
{
'id': 2,
'name': u'Nexus',
'inventory': 90,
'revenue_dp': 80,
'costprice': 100,
'revenue_cp': 50,
'num_bids_item': 8,
'num_bids_total': 7,
'inventory': 5,
'max_inventory': 10
}
]
#list all products - just for Blahh
@app.route('/products', methods=['GET'])
def get_products():
return jsonify({'products': products})
#Return if customers bidding price is accepted or not: 1 accepted, 0 not accepted
@app.route('/products/bidstatus/<int:prod_id>,<int:bidding_price>,<int:loyalty_level>', methods=['GET'])
def get_bidstatus(prod_id,bidding_price,loyalty_level):
product = [product for product in products if product['id'] == prod_id]
global bidstatus
print bidding_price, loyalty_level
Optimal_bid_price = 27
if Optimal_bid_price == bidding_price:
bidstatus = 1
else:
bidstatus = 0
if len(product) == 0:
abort(404)
return jsonify({'Bid Status': bidstatus})
#Return payment status : 1 for success, 0 for failure
@app.route('/products/payment/<int:prod_id>,<int:cust_payment_info>,<int:bidding_price>', methods=['GET'])
def get_paymentStatus(prod_id,cust_payment_info,bidding_price):
product = [product for product in products if product['id'] == prod_id]
print cust_payment_info, bidding_price
if len(product) == 0:
abort(404)
return jsonify({'Payment status': 1})
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
if __name__ == '__main__':
app.run(debug=True)