-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
117 lines (79 loc) · 2.96 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
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
from flask import Flask, request, Response, render_template , redirect, url_for
from src.model_db import (select_all_taxpayers, select_taxpayer_by_rnc, select_taxpayer_by_name, select_taxpayer_by_state)
import json
from datetime import date
app = Flask(__name__)
api_v = '/api/v1'
@app.route('/')
def home():
return redirect(url_for('doc'))
@app.route('/doc/api')
def doc():
data = request.args.get('email')
print(data)
return render_template("index.html")
@app.route(f'{api_v}/taxpayers', methods=['GET'])
def fetch_taxpayers():
limit = request.args.get('limit')
if limit:
data = select_all_taxpayers(limit)
else:
data = select_all_taxpayers()
response = json.dumps(data)
return Response(response, mimetype='application/json')
@app.route(f'{api_v}/taxpayers/by-rnc', methods=['GET'])
def fetch_taxpayer_by_rnc():
search = request.args.get('search')
limit = request.args.get('limit')
if search:
if limit:
data = select_taxpayer_by_rnc(search, limit)
else:
data = select_taxpayer_by_rnc(search)
response = json.dumps(data)
return Response(response, mimetype='application/json')
return {'message': 'you must pass rnc as argument. See the Documentation'}, 400
@app.route(f'{api_v}/taxpayers/by-name', methods=['GET'])
def fetch_taxpayer_by_name():
search = request.args.get('search')
limit = request.args.get('limit')
if search:
if limit:
data = select_taxpayer_by_name(search, limit)
else:
data = select_taxpayer_by_name(search)
response = json.dumps(data)
return Response(response, mimetype='application/json')
return {'message': 'you must pass name as argument. See the Documentation'}, 400
@app.route(f'{api_v}/taxpayers/active-state', methods=['GET'])
def fetch_active_taxpayers():
limit = request.args.get('limit')
state = 'ACTIVO'
if limit:
data = select_taxpayer_by_state(state, limit)
else:
data = select_taxpayer_by_state(state)
response = json.dumps(data)
return Response(response, mimetype='application/json')
@app.route(f'{api_v}/taxpayers/inactive-state', methods=['GET'])
def fetch_inactive_taxpayers():
limit = request.args.get('limit')
state = 'NO ACTIVO'
if limit:
data = select_taxpayer_by_state(state, limit)
else:
data = select_taxpayer_by_state(state)
response = json.dumps(data)
return Response(response, mimetype='application/json')
@app.route(f'{api_v}/taxpayers/discharged-state', methods=['GET'])
def fetch_discharged_taxpayers():
limit = request.args.get('limit')
state = 'DADO DE BAJA'
if limit:
data = select_taxpayer_by_state(state, limit)
else:
data = select_taxpayer_by_state(state)
response = json.dumps(data)
return Response(response, mimetype='application/json')
if __name__ == "__main__":
app.run(debug=True)