-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
40 lines (29 loc) · 909 Bytes
/
Copy pathapi.py
File metadata and controls
40 lines (29 loc) · 909 Bytes
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
from flask import Flask, request
from flask_restful import Resource, Api
from serialization import Serialization
from fuel import Fuel
s = Serialization()
station = s.load()
app = Flask(__name__)
api = Api(app)
class Station(Resource):
def get(self):
return s.load_json(), 200
def post(self):
obj = request.form
station.add_fuel_type(Fuel(obj["name"], int(obj["tank"])))
s.save(station)
return s.load_json(), 201
def put(self):
obj = request.form
station.spend_fuel(obj["name"], int(obj["tank"]))
s.save(station)
return s.load_json(), 200
def delete(self):
obj = request.form["name"]
station.delete_fuel_type(obj)
s.save(station)
return s.load_json(), 200
api.add_resource(Station, '/')
if __name__ == '__main__':
app.run(debug=True)