-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.py
124 lines (88 loc) · 3.4 KB
/
server.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
from flask import Flask, jsonify
import flask
from flask_cors import CORS, cross_origin
from db_backend import *
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route("/", methods=['GET'])
@cross_origin()
def home():
return "<p>Backend Active</p>"
@app.route("/search/poem", methods=['GET'])
@cross_origin()
def search_poem_controller():
args = dict(flask.request.args)
query_str = args['query_str']
query_type = args['query_type']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_poem(query_str, query_type, items_per_page, curr_page))
@app.route("/query/poem_by_id", methods=['GET'])
@cross_origin()
def query_poem_by_id_controller():
args = dict(flask.request.args)
p_id = int(args['p_id'])
return jsonify(query_poem_by_id(p_id))
@app.route("/search/author", methods=['GET'])
@cross_origin()
def search_author_controller():
args = dict(flask.request.args)
query_str = args['query_str']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_author(query_str, items_per_page, curr_page))
@app.route("/query/poem_by_author", methods=['GET'])
@cross_origin()
def query_poem_by_author_controller():
args = dict(flask.request.args)
a_id = args['a_id']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_author(a_id, items_per_page, curr_page))
@app.route("/display/author", methods=['GET'])
@cross_origin()
def display_author_controller():
args = dict(flask.request.args)
items_per_page = int(args.get('items_per_page', 100))
return jsonify(display_author(items_per_page))
@app.route("/display/rhythmic", methods=['GET'])
@cross_origin()
def display_rhythmic_controller():
args = dict(flask.request.args)
items_per_page = int(args.get('items_per_page', 100))
return jsonify(display_rhythmic(items_per_page))
@app.route("/search/rhythmic", methods=['GET'])
@cross_origin()
def search_rhythmic_controller():
args = dict(flask.request.args)
r_name = args['r_name']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_rhythmic(r_name, items_per_page, curr_page))
@app.route("/query/poem_by_rhythmic", methods=['GET'])
@cross_origin()
def query_poem_by_rhythmic_controller():
args = dict(flask.request.args)
r_id = int(args['r_id'])
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_rhythmic(r_id, items_per_page, curr_page))
@app.route("/display/collection", methods=['GET'])
@cross_origin()
def display_collection_controller():
return jsonify(display_collection())
@app.route("/query/poem_by_collection", methods=['GET'])
@cross_origin()
def query_poem_by_collection_controller():
args = dict(flask.request.args)
c_id = int(args['c_id'])
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_collection(c_id, items_per_page, curr_page))
@app.route("/query/random_poem", methods=['GET'])
@cross_origin()
def query_random_poem_controller():
return jsonify(query_random_poem())
if __name__ == '__main__':
app.run()