-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (64 loc) · 1.63 KB
/
app.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
from flask import Flask
from flask import jsonify
from flask import request
import socket
import json
from werkzeug.datastructures import ImmutableMultiDict
#!/usr/bin/env python
# -*- coding: utf-8 -*-
app = Flask(__name__)
racks = [
{
"id": 1,
"location": u"Hovedbygget, Glshuagen",
"latitude": u"63.41947",
"longitude": u"10.40093",
"parkingspots": 20,
"available_spots": 15
},
{
"id": 2,
"location": u"Torget",
"latitude": u"63.43012",
"longitude": u"10.39508",
"parkingspots": 30,
"available_spots": 29
},
{
"id": 3,
"location": u"Solsiden",
"latitude": u"63.43427",
"longitude": u"10.41275",
"parkingspots": 10,
"available_spots": 0
}
]
reservations = [
]
@app.route('/update/<int:rack_id>', methods=['PUT'])
def addRack(rack_id):
content = request.json
racks.append({
"id": rack_id,
"location": request.json.get('location'),
"latitude": request.json.get('latitude'),
"longitude": request.json.get('longitude'),
"parkingspots": 10,
"available_spots": 0
})
print(racks)
return 'all good'
@app.route('/reserve/<int:id>', methods=['PUT'])
def reserve(id):
body = request.form.to_dict()
print(body)
reservations.append(body)
return 'Reservation added'
@app.route('/reservations', methods=["GET"])
def reservation():
return jsonify(reservations)
@app.route('/', methods=['GET'])
def index():
return jsonify({'racks': racks})
if __name__ == "__main__":
app.run(debug=True)