-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
527 lines (469 loc) · 18.8 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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
from types import MethodType
from flask import Flask, json, jsonify, request
from base64 import b64encode, b64decode
import base64
from controller import regionController as region, servicioExtraController as servicioExtra
from controller import actaController, departmentController, clientsController, comunaController, ciudadController, inventarioController, inventarioDepartamentoController
from controller import usuarioController, maintainsDepartmentController, typeUserController, loginController, reservaController, transportController
import random
from transbank.error.transbank_error import TransbankError
from transbank.webpay.webpay_plus.transaction import Transaction
app = Flask(__name__)
@app.route('/')
def inicio():
return 'PÁGINA DE INICIO'
@app.route('/api/regions', methods=['GET'])
def getRegions():
regiones = [regionList for regionList in region.getRegiones()]
# listRegiones = json.dumps(regiones)
print(regiones)
if (len(regiones) > 0):
return jsonify({"regions":regiones})
else:
return jsonify({"regions": []})
@app.route('/api/regions', methods=['POST'])
def addRegion():
try:
data = request.get_json()
print(data['id'], data['nombre'])
region.addRegion(data['id'], data['nombre'])
return jsonify({'ok': True})
except Exception as err:
return
@app.route('/api/communes')
def getComuna():
comuna = [comunaList for comunaList in comunaController.getComuna()]
print(comuna)
if (len(comuna) > 0):
return jsonify({"communes":comuna})
else:
return jsonify({"communes":[]})
@app.route('/api/cities')
def getCiudad():
ciudad = [ciudadList for ciudadList in ciudadController.getCiudad()]
print(ciudad)
if (len(ciudad) > 0):
return jsonify({"cities":ciudad})
else:
return jsonify({"cities":[]})
@app.route('/api/acta')
def getActa():
actas = [listaActa for listaActa in actaController.getActa()]
print(actas)
if (len(actas) > 0 ):
return jsonify({'actas': actas})
else:
return jsonify({"message":'no existen actas'})
@app.route('/api/departments', methods=['GET'])
def getDepartments():
print('test////////////////////////////')
departamentos = [departmentList for departmentList in departmentController.getDepartments()]
if (len(departamentos)> 0):
return jsonify({'departments':departamentos })
else:
return jsonify({'departments':[] })
@app.route('/api/departments', methods=['POST'])
def addDepartment():
try:
print('I work?')
data = request.get_json()
departmentController.addDepartment(data['name']
,data['address']
,data['totalRooms']
,data['totalParking']
,data['totalBaths']
,data['internet']
,data['tv']
,data['heating']
,data['furnished']
,data['departmentPrice']
,data['departmentStatus']
,data['departmentDesc']
,data['idCommune']
,data['imgB64'])
return jsonify({'ok': True})
except Exception as err:
print(err)
return jsonify({'ok': False})
@app.route('/api/departments', methods=['PUT'])
def updateDepartment():
try:
data = request.get_json()
departmentController.updateDepartment(data['id'],data['name'], data['address'],data['totalRooms'], data['totalParking'],data['totalBaths'],
data['internet'],data['tv'],data['heating'],data['furnished'],data['departmentPrice'],
data['departmentStatus'],data['departmentDesc'],data["idCommune"])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/departments', methods=['DELETE'])
def deleteDepartment():
try:
data = request.get_json()
departmentController.deleteDepartment(data['id'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/inventories', methods=['GET'])
def getInventory():
inventario = [inventarioList for inventarioList in inventarioController.getInventories()]
if (len(inventario)> 0):
return jsonify({'inventories':inventario })
else:
return jsonify({'inventories':[] })
@app.route('/api/inventoriesDepartment', methods=['GET'])
def getInventoryDepartments():
inventario = [inventarioList for inventarioList in inventarioDepartamentoController.getInventoryDepartment()]
if (len(inventario)> 0):
return jsonify({'inventoriesDepartments':inventario })
else:
return jsonify({'inventoriesDepartments':[] })
@app.route('/api/inventoriesDepartment', methods=['POST'])
def addInventoryDepartment():
try:
data = request.get_json()
inventarioDepartamentoController.addInventoryDepartment(data['quantity'],data["departmentId"],data["inventoryId"])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/inventoriesDepartmentById', methods=['GET'])
def getInventoryDepartmentsById():
data = request.args['id']
inventario = [inventarioList for inventarioList in inventarioDepartamentoController.getInventoryDepartmentById(data)]
if (len(inventario)> 0):
return jsonify({'inventoriesDepartments':inventario })
else:
return jsonify({'inventoriesDepartments':[] })
@app.route('/api/inventoriesDepartment', methods=['DELETE'])
def deleteInventoryDepartment():
try:
data = request.get_json()
inventarioDepartamentoController.deleteInventoryDepartment(data["id"])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/users', methods=['GET'])
def getUsers():
user = [userList for userList in usuarioController.getUsuarios()]
if (len(user)> 0):
return jsonify({'users':user })
else:
return jsonify({'users':[] })
@app.route('/api/users', methods=['POST'])
def userInit():
try:
data = request.get_json()
usuarioController.usuarioInit(data['firstName'],data['rut'],data['lastNameP'],data['lastNameM'], data['dateOfBirth'], data['mail'],
data['phone'], data['pass'], data['idCommune'], data['idType'])
print(data)
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/users', methods=['PUT'])
def updateUser():
try:
data = request.get_json()
usuarioController.updateUser(data['id'],data['rut'],data['firstName'],data['lastNameP'],data['lastNameM'], data['dateOfBirth'], data['mail'],
data['phone'], data['pass'], data['idCommune'], data['idType'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/users', methods=['DELETE'])
def deleteUser():
try:
data = request.get_json()
usuarioController.deleteUser(data['id'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/maintainsDepartments', methods=['POST'])
def addMaintainDepartment():
try:
data = request.get_json()
maintainsDepartmentController.addMaintainsDepartments(data['initDate'],data["finishDate"],data["userId"],data["departmentId"])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/maintainsDepartments',methods=['GET'])
def getMaintainsDepartments():
maintains = [maintainsList for maintainsList in maintainsDepartmentController.getMaintainsDepartments()]
if (len(maintains)> 0):
return jsonify({'maintainsDepartments':maintains })
else:
return jsonify({'maintainsDepartments':[] })
@app.route('/api/maintainsDepartmentsById',methods=['GET'])
def getMaintainsDepartmentsById():
data = request.args['id']
print(data)
maintains = [maintainsList for maintainsList in maintainsDepartmentController.getMaintainDepartmentById(data)]
# print(data)
if (len(maintains)> 0):
return jsonify({'maintainsDepartments':maintains })
else:
return jsonify({'maintainsDepartments':[] })
@app.route('/api/typeUser', methods=['GET'])
def getTypeUser():
typeUser = [typeUserList for typeUserList in typeUserController.getTypeUser()]
if(len(typeUser) > 0):
return jsonify({'typeUsers': typeUser})
else:
return jsonify({'typeUsers': []})
@app.route('/api/validateLogin', methods=['POST'])
def validateLogin():
try:
json = request.get_json()
datos = loginController.validateLogin(json['mail'],json['password'])
# print(datos)
if(len(datos)> 0):
return jsonify({'user': datos})
else:
return jsonify({'user': []})
except Exception as err:
return print(err)
@app.route('/api/departmentById', methods=['GET'])
def getDepartmentById():
data = request.args['id']
department = [departmentList for departmentList in departmentController.getDepartmentById(data)]
print(department)
if (len(department) > 0):
return jsonify({'department': department})
else:
return jsonify({'department': []})
@app.route('/api/departmentByDisponibility', methods=['GET'])
def getDepartmentByDisponibility():
department = [departmentList for departmentList in departmentController.getDepartmentByDisponibility(1)]#request.args['disponibility']
print(department)
if(len(department) > 0):
return jsonify({'departments': department})
else:
return jsonify({'department': []})
@app.route('/api/updateDisponibility', methods=['PUT'])
def updateDisponibility():
try:
data = request.get_json()
departmentController.updateDisponibility(data['id'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/reserve', methods=['GET'])
def getReserve():
reserva = [reservaList for reservaList in reservaController.getReservas()]
print(reserva)
if(len(reserva) > 0):
return jsonify({'reserves': reserva})
else:
return jsonify({'reserves': []})
@app.route('/api/reserve', methods=['POST'])
def addReserve():
try:
data = request.get_json()
reservaController.addReserva(data['checkInPlanning'],data['checkOut'],data['totalDays'],
data['totalAdults'], data['totalKids'], data['totalBabies'],data['totalReserve'],
data['statusReserve'], data['departmentId'],data['clientId'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/reserve', methods=['DELETE'])
def deleteReserve():
try:
data = request.get_json()
reservaController.deleteReserve(data['id'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/checkInReserve', methods=['PUT'])
def updateCheckIn():
try:
data = request.get_json()
reservaController.updateCheckIn(data['checkIn'], data['reserveId'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/multa', methods=['POST'])
def addMulta():
try:
data = request.get_json()
print(data)
reservaController.addMulta(data['quantity'], data['subTotal'], data['idActa'], data['idReserve'] )
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/multa', methods=['DELETE'])
def deleteMulta():
try:
data = request.get_json()
print(data)
reservaController.deleteMulta(data['id'])
return jsonify({'ok': True})
except Exception as err:
return print(err)
@app.route('/api/multa', methods=['GET'])
def getMulta():
try:
data = request.args["id"]
multa = [multaList for multaList in reservaController.getMulta(data)]
print(multa)
if(len(multa)> 0):
return jsonify({'fines': multa})
else:
return jsonify({'fines': []})
except Exception as err:
print(err)
@app.route('/api/reserveServex', methods=['GET'])
def getReservaServex():
try:
reservaServex = [reservaServexList for reservaServexList in reservaController.getReservaServex(request.args['id'])]
print(reservaServex)
if(len(reservaServex)> 0):
return jsonify({'services': reservaServex})
else:
return jsonify({'services': []})
except Exception as err:
print(err)
@app.route('/api/reserveServex', methods=['POST'])
def addReservaServex():
try:
data = request.get_json()
reservaController.addReservaServex(data['cantidad'],data['subtotal'],data['serv_id'],data['reserv_id'])
return jsonify({'ok': True})
except Exception as err:
return jsonify({'ok': err})
@app.route('/api/reserveServex', methods=['DELETE'])
def deleteReservaServex():
try:
data = request.get_json()
reservaController.deleteReservaServex(data['id'])
return jsonify({'ok': True})
except Exception as err:
return jsonify({'message':'no se pudo eliminar la reserva'})
@app.route('/api/extraServices', methods=['GET'])
def getServExtra():
servicios = [serviciosList for serviciosList in servicioExtra.getServExtra()]
# print(servicios)
if servicios:
return jsonify({'servicios': servicios})
else:
return jsonify({"servicios":[]})
# @app.route('/api/reserveByUser')
# def getReservaByUser():
# try:
# data = request.args['id']
# reserveByUser = [lista for lista in reservaController.getReservaByUser(data)]
# if len(reserveByUser) > 0:
# return jsonify({'reserve': reserveByUser})
# else:
# return jsonify
@app.route('/api/transport', methods=['GET'])
def getTransports():
transport = [transports for transports in transportController.getTransports()]
print(transport)
if(len(transport) > 0):
return jsonify({'transports': transport})
else:
return jsonify({'transports': []})
@app.route('/api/transport', methods=['POST'])
def addTransports():
try:
data = request.get_json()
transportController.addTransport(data['place'],data['time'],
data['vehicle'],data['idReserve'],data['idWorker'])
return jsonify({'ok': True})
except Exception as err:
return jsonify({'ok': err})
@app.route('/api/transport', methods=['PUT'])
def updateTransport():
try:
data = request.get_json()
transportController.updateTransport(data['id'],data['place']
,data['time'],data['vehicle'],data['idReserve'],data['idWorker'])
return jsonify({'ok': True})
except Exception as err:
return
@app.route('/api/transport', methods=['DELETE'])
def deleteTransport():
try:
data = request.get_json()
transportController.deleteTransport(data['id'])
return jsonify({'ok': True})
except Exception as err:
return jsonify({'message':'no se pudo eliminar el transporte'})
@app.route('/api/getReservaByUser')
def getReservaByUser():
data = request.args['id']
reserva = [lista for lista in reservaController.getReservaByUser(data)]
print(reserva)
if(len(reserva) > 0):
return jsonify({"reserve" : reserva})
else:
return jsonify({"reserve" : []})
@app.route('/api/getCheckout')
def getCheckout():
try:
data = request.args["id"]
reserva = [reservaList for reservaList in reservaController.getReservaById(data)]
acta = [actalist for actalist in reservaController.getMulta(data)]
servex = [servexList for servexList in reservaController.getReservaServex(data)]
print(acta)
return jsonify({'reserve': reserva, 'fines' : acta, 'servex' : servex})
except Exception as err:
print(err)
@app.route('/api/putCheckout', methods=['PUT'])
def putCheckout():
try:
data = request.get_json()
reservaController.putCheckout(data["id"])
reservaController.createOrderPay(data["id"])
return jsonify({'ok': True})
except Exception as err:
print(err)
@app.route('/api/pagoInfo', methods=['POST'])
def pagoInfo():
try:
data = request.get_json()["token"]
print(data)
response = Transaction.commit(data)
print(str(response))
return jsonify({"response": str(response)})
except Exception as err:
print(err)
return str(err)
@app.route('/api/pago', methods=["GET"])
def pago():
try:
# El SDK apunta por defecto al ambiente de pruebas, no es necesario configurar lo siguiente
# Transaction.webpay.webpay_plus.webpay_plus_default_commerce_code = 597055555532
# Transaction.webpay.webpay_plus.default_api_key = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"
# Transaction.webpay.webpay_plus.default_integration_type = IntegrationType.TEST
# response = Transaction.webpay.webpay_plus.create("PRUEBABUY_ORDER", "123", 1000, "https://www.google.cl")
data = request.args['id']
response = reservaController.getOrderPayById(data) #Deberia ser get order pay y agregar un update
print("Webpay Plus Transaction.create")
buy_order = str(random.randrange(1000000, 99999999))
session_id = str(random.randrange(1000000, 99999999))
amount = random.randrange(10000, 1000000)
return_url = request.url_root + 'webpay-plus/commit'
create_request = {
"buy_order": buy_order,
"session_id": session_id,
"amount": amount,
"return_url": "http://localhost:4000/"
}
responseTrans = Transaction.create(buy_order, session_id, response[0]["totalReserve"], "http://localhost:4000/client/pago")
# print(responseTrans.token, responseTrans.url)
# response = Transaction.commit(token = responseTrans.token)
reservaController.updateOrderPay(data)
return jsonify({"url" : str(responseTrans.url), "token" : str(responseTrans.token)})
except Exception as err:
print(err)
@app.route('/api/getOrderByUser', methods=["GET"])
def getOrderByUser():
try:
response = [orders for orders in reservaController.getOrderPayByUser(request.args['id'])]
print(response)
if(len(response)> 0):
return jsonify({'order': response})
else:
return jsonify({'order': []})
except Exception as err:
print(err)
if __name__ == '__main__':
app.run(host="0.0.0.0",debug = True, port = 4000)