Exemplo n.º 1
0
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')
Exemplo n.º 2
0
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')
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
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')
Exemplo n.º 6
0
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')
Exemplo n.º 7
0
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')