def PutDevice(name): try: if request.is_json: content = request.json status = InventDB.putDevice(content, name) if status == 0: return Httpstatus.ok_server_put('ok') elif status == 1: return Httpstatus.not_found('not found') else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except Exception as e: print(e) return int_server('server error')
def putLugar(id): try: print(request.is_json) if request.is_json: content = request.json status = LugarDB.putLugar(id, content) if status == 0: return Httpstatus.ok_server_put('ok') elif status == 1: return Httpstatus.not_found('not found') else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except Exception as e: print(e) return Httpstatus.int_server('server error')
def putMove(id): try: print(request.is_json) if request.is_json: content = request.json print(content) status = TypemovesDB.putMove(id, content) if status == 0: return Httpstatus.ok_server_put('ok') elif status == 1: return Httpstatus.not_found('not found') else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except: print('error') return Httpstatus.int_server('server error')
def GetDevicemarca(name): try: data = InventDB.getDevicesbymarca(name) if data == 1: return Httpstatus.not_found('not found') if data == 2: return Httpstatus.int_server('server error') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def GetReport(name): try: data = ReportDB.getReportsbycode(name) if data == 1: return Httpstatus.not_found('not found') if data == 2: return Httpstatus.int_server('server error') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def GetLugar(name): try: data = LugarDB.getLugar(name) if data == 2: return Httpstatus.int_server('server error') elif data == 1: return Httpstatus.not_found('not found') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error') return 'postuser'
def GetMovementsbyId(id): try: data = HistorialDB.getHistorialbyID(id) if data == 2: return Httpstatus.int_server('server error') elif data == 1: return Httpstatus.not_found('not found') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def GetReportbyname(): try: name = request.args.get('producto') data = ReportDB.getReportsbyname(name) if data == 1: return Httpstatus.not_found('not found') if data == 2: return Httpstatus.int_server('server error') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def GetDevicebyname(): try: name = request.args.get('nombre') data = InventDB.getDevicesbyname(name) if data == 1: return Httpstatus.not_found('not found') if data == 2: return Httpstatus.int_server('server error') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def PostMove(): try: if request.is_json: content = request.get_json() status = TypemovesDB.postMove(content) if status == 0: return Httpstatus.ok_server_post() else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except Exception as e: print(e) return Httpstatus.int_server('server error')
def searchmissing(id): try: if id is None: return Httpstatus.bad_request('bad request') data = HistorialDB.SearchMissingEntries(id) if data == 2: return Httpstatus.int_server('server error') elif data == 1: return Httpstatus.not_found('not found') return data, 200, {'ContentType': 'application/json'} except: print("error") return Httpstatus.int_server('server error')
def PostHistorial(): try: print(request.is_json) if request.is_json: content = request.get_json() status = HistorialDB.postHistorial(content) if status == 0: return Httpstatus.ok_server_post() else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except: return Httpstatus.int_server('server error')
def GetMovementsbysearch(): try: #["movimiento","lugar","usuario","producto","fecha","modelo","marca","codigo","serie"] lista = [] try: lista.append(request.args.get('IDmovimiento')) lista.append(request.args.get('IDtipomov')) lista.append(request.args.get('IDlugar')) lista.append(request.args.get('IDusuario')) lista.append(request.args.get('producto')) lista.append(request.args.get('fechamovimiento')) lista.append(request.args.get('modelo')) lista.append(request.args.get('marca')) lista.append(request.args.get('codigo')) lista.append(request.args.get('serie')) if request.args.get('fechamovimiento') != "null": datetime.datetime.strptime(request.args.get('fechamovimiento'), "%Y-%m-%d").date() except Exception as e: print(e) return Httpstatus.bad_request('bad_request') #movimiento = request.args.get('movimiento') if len(lista) != 10: return Httpstatus.bad_request('bad request') data = HistorialDB.getHistorialbysearch(lista) if data == 2: return Httpstatus.int_server('server error') elif data == 1: return Httpstatus.not_found('not found') return data, 200, {'ContentType': 'application/json'} except Exception as e: print(e) return Httpstatus.int_server('server error')
def PostLugar(): try: if request.is_json: content = request.get_json() status = LugarDB.postLugar(content) if status == 0: return Httpstatus.ok_server_post() elif status == 2: return Httpstatus.int_server('server error') elif status == 1: return Httpstatus.conflict('Conflicto') else: return Httpstatus.bad_request('bad request') except Exception as e: print(e) return Httpstatus.int_server('server error')
def deldevice(id): try: status = InventDB.delDevice(id) if status == 0: return Httpstatus.ok_server_put('ok') elif status == 1: return Httpstatus.not_found('not found') elif status == 2: return Httpstatus.int_server('server error') else: return Httpstatus.conflict('Conflicto al borrar') except: return Httpstatus.int_server('server error')
def delhistorial(id): try: status = HistorialDB.delhistorialByID(id) if status == 0: return Httpstatus.ok_server_put('ok') elif status == 1: return Httpstatus.not_found('not found') elif status == 2: return Httpstatus.int_server('server error') else: return Httpstatus.conflict('Conflicto al borrar') except: return Httpstatus.int_server('server error')
def Getdevicesbysearch(): try: #["codigo","producto","fecha","modelo","marca","serie"] lista = [] try: lista.append(request.args.get('codigo')) lista.append(request.args.get('producto')) lista.append(request.args.get('fecha')) lista.append(request.args.get('modelo')) lista.append(request.args.get('marca')) lista.append(request.args.get('serie')) if request.args.get('fecha') != "null": datetime.datetime.strptime(request.args.get('fecha'), "%Y-%m-%d").date() except Exception as e: print(e) return Httpstatus.bad_request('bad_request') #movimiento = request.args.get('movimiento') if len(lista) != 6: return Httpstatus.bad_request('bad request') data = InventDB.getDevicesbysearch(lista) if data == 2: return Httpstatus.int_server('server error') elif data == 1: return Httpstatus.not_found('not found') return data, 200, {'ContentType': 'application/json'} except Exception as e: print(e) return Httpstatus.int_server('server error')
def PostDevice(): try: print(request.is_json) if request.is_json: content = request.get_json() status = InventDB.postDevice(content) if status == 0: return Httpstatus.ok_server_post() elif status == 2: return Httpstatus.int_server('server error') elif status == 1: return Httpstatus.conflict('ya existente') else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except: return Httpstatus.int_server('server error')
def ValidateSame(): try: print(request.is_json) if request.is_json: content = request.get_json() status = InventDB.ValidateSamePlaces(content) if status == 0: return Httpstatus.ok_server_post() elif status == 2: return Httpstatus.conflict('not the same') elif status == 1: return Httpstatus.not_found('not found') else: return Httpstatus.int_server('server error') else: return Httpstatus.bad_request('bad request') except: return Httpstatus.int_server('server error')