-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (42 loc) · 1.39 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
import logging
import pprint
import os
from flask import Flask, jsonify
from flask_restful import Resource, Api, reqparse
from flask_cors import CORS
from dao.donkey_dao import DonkeyDAO
from util.config import host_ip
app = Flask(__name__)
CORS(app)
api = Api(app)
class Donkeys(Resource):
def get(self):
print('getting all donkeys')
return DonkeyDAO().get_all(), 200
def post(self):
print('posting a donkey')
parser = reqparse.RequestParser()
return DonkeyDAO().post(parser), 200
class Donkey(Resource):
def get(self, donkey_id):
print('getting one donkey')
return DonkeyDAO().get_by_id(donkey_id), 200
def delete(self, donkey_id):
print('deleting all donkeys')
return DonkeyDAO().remove(donkey_id), 200
class Donkey_Populate(Resource):
def post(self):
print('populating with random donkeys')
parser = reqparse.RequestParser()
return DonkeyDAO().populate_with_random(parser), 200
class Donkey_Purge(Resource):
def post(self):
print('purging donkeys')
return DonkeyDAO().purge(), 200
api.add_resource(Donkeys, '/donkeys')
api.add_resource(Donkey, '/donkeys/<string:donkey_id>')
api.add_resource(Donkey_Populate, '/donkeys/populate')
api.add_resource(Donkey_Purge, '/donkeys/purge')
if __name__ == '__main__':
app.debug = True
app.run(host=host_ip, port=5000, debug=True)