-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
380 lines (286 loc) · 9.92 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
from flask import Flask, jsonify, request
from middleware.auth import AuthUser
from api.user import User
from api.rental import SendingInformation
from util.util import response_false, response_incomplete, verifyExist, verifyRequired
import time
app = Flask(__name__)
@app.route('/', methods = ['GET'])
def index():
if (request.method == 'GET'):
response_fail = {
'response' : 'Para usar este servicio lea la documentacion',
'documentacion' : ''
}
return jsonify(response_fail), 200
@app.route('/login', methods = ['GET'])
def loginauth():
if (request.method == 'GET'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
data_obligatorios = [
_arg_email,
_arg_password
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
r_status = 200
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
else:
r_status = 200
return jsonify({"response": "Loguea con exito"}), r_status
@app.route('/createUser', methods = ['POST'])
def createUser():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
data_obligatorios = [
_arg_email,
_arg_password
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
# Se llama la clase que tiene el metodo de creacion de usuario
__user = User(_arg_email,_arg_password)
r_create = __user.createUser()
r_status = 200
if (r_create == False):
r_create = response_false
r_status = 401
return jsonify(r_create), r_status
@app.route('/forgotPassword', methods = ['POST'])
def fpassword():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
data_obligatorios = [
_arg_email
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
__auth = AuthUser(_arg_email)
r_fpassword = __auth.forgotPassword()
r_status = 200
if (r_fpassword == False):
r_fpassword = response_false
r_status = 401
return jsonify(r_fpassword), r_status
@app.route('/alquilar', methods = ['POST'])
def addData():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
_arg_modelo = verifyExist(arg_param, 'modelo')
_arg_marca = verifyExist(arg_param, 'marca')
_arg_year = verifyExist(arg_param, 'year')
_arg_color = verifyExist(arg_param, 'color')
_arg_responsable = verifyExist(arg_param, 'responsable')
data_obligatorios = [
_arg_email,
_arg_password,
_arg_modelo,
_arg_marca,
_arg_year,
_arg_color,
_arg_responsable
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 400
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
r_status = 200
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
data = {
'uid': r_auth['localId'],
'modelo': _arg_modelo,
'color': _arg_color,
'marca': _arg_marca,
'year': _arg_year,
'responsable': _arg_responsable,
'dia': time.strftime("%d/%m/%y"),
'status': 'pendiente'
}
# Se llama la clase que tiene el metodo de insercion de data
__send = SendingInformation(u'rentals', data)
s_add = __send.addData()
s_status = 200
if (s_add == False):
s_add = response_false
s_status = 401
return jsonify(s_add), s_status
@app.route('/alquileres/user', methods = ['POST'])
def getdata_user():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
_arg_filter = verifyExist(arg_param, 'filtro')
data_obligatorios = [
_arg_email,
_arg_password,
_arg_filter
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
if(_arg_filter != 'todo' and _arg_filter != 'pendiente' and _arg_filter != 'entregado'):
return jsonify(response_false), 401
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
uid = r_auth['localId']
__send = SendingInformation(u'rentals', _arg_filter, uid)
s_get = __send.getDataxUser()
s_status = 200
if (s_get == False):
s_get = response_false
s_status = 401
return jsonify(s_get), s_status
@app.route('/alquileres', methods = ['POST'])
def getdata_all():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
_arg_filter = verifyExist(arg_param, 'filtro')
data_obligatorios = [
_arg_email,
_arg_password,
_arg_filter
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
if(_arg_filter != 'todo' and _arg_filter != 'pendiente' and _arg_filter != 'entregado'):
return jsonify(response_false), 401
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
__send = SendingInformation(u'rentals', _arg_filter)
s_get = __send.getData()
s_status = 200
if (s_get == False):
s_get = response_false
s_status = 401
return jsonify(s_get), s_status
@app.route('/cerrarAlquiler', methods = ['POST'])
def closeData():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
_arg_document = verifyExist(arg_param, 'id')
_arg_filter = verifyExist(arg_param, 'filtro')
data_obligatorios = [
_arg_email,
_arg_password,
_arg_document,
_arg_filter
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
if(_arg_filter != 'entregado'):
return jsonify(response_false), 401
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
data = {
'document': _arg_document,
'filtro': _arg_filter
}
__send = SendingInformation(u'rentals', data)
s_delete = __send.closeData()
s_status = 200
if (s_delete == False):
s_delete = response_false
s_status = 400
return jsonify(s_delete), s_status
@app.route('/corregirDatos', methods = ['POST'])
def updateData():
if (request.method == 'POST'):
arg_param = request.get_json()
# Se verifica si los parametros existen
_arg_email = verifyExist(arg_param, 'email')
_arg_password = verifyExist(arg_param, 'password')
_arg_document = verifyExist(arg_param, 'id')
_arg_color = verifyExist(arg_param, 'color')
_arg_marca = verifyExist(arg_param, 'marca')
_arg_year = verifyExist(arg_param, 'year')
_arg_responsable = verifyExist(arg_param, 'responsable')
_arg_modelo = verifyExist(arg_param, 'modelo')
data_obligatorios = [
_arg_email,
_arg_password,
_arg_document
]
verify_obligatorios = verifyRequired(data_obligatorios)
if (verify_obligatorios == False):
return jsonify(response_incomplete), 401
# Se llama la clase que tiene el metodo de autentificacion de usuario
__auth = AuthUser(_arg_email,_arg_password)
r_auth = __auth.auth_user()
if (r_auth == False):
r_auth = response_false
r_status = 401
return jsonify(r_auth), r_status
udata_list = {}
if (_arg_color != None):
udata_list['color'] = _arg_color
if (_arg_marca != None):
udata_list['marca'] = _arg_marca
if (_arg_year != None):
udata_list['year'] = _arg_year
if (_arg_responsable != None):
udata_list['responsable'] = _arg_responsable
if (_arg_modelo != None):
udata_list['modelo'] = _arg_modelo
data = {
'document': _arg_document,
'udata': udata_list
}
__send = SendingInformation(u'rentals', data)
s_update = __send.updateData()
s_status = 200
if (s_update == False):
s_update = response_false
s_status = 401
return jsonify(s_update), s_status
if __name__ == '__main__':
app.run(debug=True)