-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
78 lines (60 loc) · 2.17 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
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
from controller import *
import json
app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/fakultas-prodi', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type','application/json'])
def all():
data = get_all()
response = {'data': data}
return jsonify(response), 200
@app.route('/fakultas', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type','application/json'])
def list_fakultas():
data = get_list_fakultas()
response = {'data': data}
return jsonify(response), 200
@app.route('/fakultas/<nama_fakultas>/prodi', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type','application/json'])
def list_prodi_fakultas(nama_fakultas):
data = get_list_prodi_fakultas(nama_fakultas)
if data is None:
message = []
desc = {
"status": "404",
"title": "Tidak ditemukan",
"detail": "Prodi dari fakultas bersangkutan tidak ditemukan"
}
message.append(desc)
response = {'errors': message}
return jsonify(response), 404
response = {'data': data}
return jsonify(response), 200
@app.route('/prodi', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type','application/json'])
def list_prodi():
data = get_list_prodi()
response = {'data': data}
return jsonify(response), 200
@app.route('/prodi/<kode_prodi>', methods=['GET'])
@cross_origin(origin='localhost', headers=['Content-Type','application/json'])
def prodi(kode_prodi):
data = get_prodi(kode_prodi)
if data is None:
message = []
desc = {
"status": "404",
"title": "Tidak ditemukan",
"detail": "Kode prodi tidak ditemukan"
}
message.append(desc)
response = {'errors': message}
return jsonify(response), 404
response = {'data': data}
return jsonify(response), 200
if __name__ == '__main__':
app.run(debug=True, port=5000)