def post(self, hotel_id):
        
        if HotelModel.find_hotel(hotel_id):
            return {"message":"Hotel id '{}' already exists".format(hotel_id)},400 #erro

        dados = Hotel.argumentos.parse_args()
        hotel = HotelModel(hotel_id, **dados) 
        
        if not SiteModel.find_by_id(dados.get('site_id')):
            return {'message': 'O hotel precisa estar associado a um site id valido'}

        try:
            hotel.save_hotel()
        except:
            return{'Message':'Erro ao salvar no banco de dados.'}
        
        return hotel.json()
    def post(self, hotel_id):

        if HotelModel.find_hotel(hotel_id):
            return {"message": "Hotel id '{}' already exists.".format(hotel_id)}, 400

        kwargs = Hotel.arguments.parse_args()
        hotel = HotelModel(hotel_id, **kwargs)
        try:
            hotel.save_hotel()
        except:
            return (
                {
                    "message": "An internal error ocurred while trying to save a new hotel."
                },
                500,
            )
        return hotel.json()
Exemple #3
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel iD '{}' alread exists.".format(hotel_id)
            }, 400  #bad request

        dados = Hotel.argumentos.parse_args(
        )  #referenciando a classe, usando o nome HOTEL
        hotel = HotelModel(
            hotel_id, **dados
        )  #agora sao objetos, e sao coletados  a partir da pasta models
        try:  #tento salvar(usadno a função save_hotel)
            hotel.save_hotel()
        except:  #caso nao consiga salvar, eu gero uma mensagem de erro com o codigo 500 (erro interno do servidor)
            {"message": "An internal error ocurred trying to save hotel."}, 500
        return hotel.json(
        )  #caso tudo funcione, eu retorno o objeto hotel convertido para json
Exemple #4
0
 def put(self, hotel_id):
     dados = Hotel.argumentos.parse_args()
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     if hotel_encontrado:
         hotel_encontrado.update_hotel(**dados)
         try:
             hotel_encontrado.save_hotel()
         except:
             {'message': 'An error ocurred trying to update hotel.'}, 500 # Internal Server Error
         return hotel_encontrado.json(), 200 # ok
     
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         {'message': 'An error ocurred trying to save hotel.'},500 # Internal Server Error
     return hotel.json(), 201 # created
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()
        hotel_persistido = HotelModel.find_hotel(hotel_id)
        if hotel_persistido:
            hotel_persistido.update_hotel(**dados)
            try:
                hotel_persistido.save_hotel()
            except:
                return {'message': 'Internal error'}, 500
            return hotel_persistido.json(), 200

        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {'message': 'Internal error'}, 500
        return hotel.json(), 201
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()

        found_hotel = HotelModel.find_hotel(hotel_id)

        if found_hotel:
            found_hotel.update_hotel(**dados)
            found_hotel.save_hotel()
            return found_hotel.json(), 200

        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {'message': 'Internal Error while saving in Database'}, 500

        return hotel.json(), 201
Exemple #7
0
    def put(self, hotel_id):

        dados = Hotel.argumentos.parse_args()
        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200
        novo_hotel = HotelModel(hotel_id, **dados)
        try:
            novo_hotel.save_hotel()
        except:
            return {
                'messege': 'An internal error ocorred trying to save hotel'
            }, 500  #internal server error

        return novo_hotel, 201
Exemple #8
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}' already exists.".format(hotel_id)
            }, 400

        dados = Hotel.argumentos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

        try:
            hotel.save_hotel()
        except:
            return {
                'message': 'An internal error ocurred trying to save hotel.'
            }, 500

        return hotel.json(), 200
Exemple #9
0
    def put(self, hotel_id):
        dados = self.argumentos.parse_args()

        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200  # success

        hotel = HotelModel(hotel_id, **dados)

        try:
            hotel.save_hotel()
        except:
            return {'msg': 'Erro inesperado.'}, 500

        return hotel.json(), 201  # created
Exemple #10
0
 def put(self, hotel_id):
 #put method
     #verifica se ja esxiste hotel e attualiza
     data = Hotel.arguments.parse_args()
     hotel_finded = Hotel.find_hotel(hotel_id)
     if hotel_finded:
         hotel_finded.update_hotel(**data)
         hotel_finded.save_hotel()
         return hotel_finded.json(), 200
     
     #se nao estiver cadastrado cria um novo
     hotel = HotelModel(hotel_id, **data)
     try:
         hotel.save_hotel()
     except: 
         return {'message': 'An internal error ocurred trying to save hotel.'}, 500 #internal server error 
     
     return hotel.json(), 201 #  201 = criado
Exemple #11
0
    def put(self, hotel_id):
        # Filtro
        dados = Hotel.argumentos.parse_args()
        hotel_encontrado = HotelModel.find_hotel(hotel_id)

        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200

        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {
                'message': 'An error occurred while saving the hotel'
            }, 500  # Internal Server Error
        return hotel.json(), 201  # created
 def put(self, hotel_id):
     
     dados = Hotel.argumentos.parse_args()
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     
     if hotel_encontrado:
         hotel_encontrado.update_hotel(**dados)
         hotel_encontrado.save_hotel()
         return hotel_encontrado.json(), 200 #se foi atualizado um hotel já existente 
     
     hotel = HotelModel(hotel_id, **dados)
     
     try:
         hotel.save_hotel()
     except:
         return{'Message':'Erro ao salvar no banco de dados.'}
     
     return hotel.json(), 201 #se foi criado um novo hotel
Exemple #13
0
    def put(self, hotel_id):

        dados = Hotel.atributos.parse_args()
        hotel_encontrado = HotelModel.find_hotel(hotel_id)

        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200  # Ok
        hotel = HotelModel(hotel_id, **dados)

        try:
            hotel.save_hotel()
        except:
            return {
                'message': 'An Internal Error Ocurres Trying To Save Hotel.'
            }, 500  # Internal Server Error
        return hotel.json(), 201  # Created
Exemple #14
0
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()
        #novo_hotel = {'hotel_id' : hotel_id, **dados }
        #hotel_objeto = HotelModel(hotel_id, **dados)
        #novo_hotel = hotel_objeto.json()
        hotel_encontrado = HotelModel.find_hotel(hotel_id)

        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200 # OK
        
        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except: 
            return {'message': 'error ocurred trying to put hotel.'}, 500 #Internal server 500
        #hoteis.append(novo_hotel)
        return hotel.json(), 201 # created criado
Exemple #15
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {"message": f"Hotel ID ({hotel_id}) already exists!"}

        dados = Hotel.arguments.parse_args()

        if not SiteModel.find_by_id(dados.get('site_id')):
            return {"message": "Site ID not found!"}, 404

        obj_hotel = HotelModel(hotel_id, **dados)

        try:
            obj_hotel.save_hotel()
        except:
            return {
                "message": "An internal error ocurred trying to save hotel."
            }, 500

        return obj_hotel.toJson(), 200
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}' already exists.".format(hotel_id)
            }, 400

        dados = Hotel.argumentos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

        if not SiteModel.find_by_id(dados['site_id']):
            return {
                'message': 'The hotel must be associated to a valid site id.'
            }, 400

        try:
            hotel.save_hotel()
        except:
            return {'message': 'An internal error occured to save hotel.'}, 500
        return hotel.json()
Exemple #17
0
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()

        finded_hotel = HotelModel.find_hotel(hotel_id)

        if finded_hotel:
            finded_hotel.update_hotel(**dados)
            try:
                finded_hotel.save_hotel()
            except:
                return {'message':'An internal error ocurred trying to save hotel.'}, 500 #Internal server error
            return finded_hotel.json(), 200 #Success

        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {'message':'An internal error ocurred trying to save hotel.'}, 500 #Internal server error

        return hotel.json(), 201 #Created
 def put(self, id):
     data = Hotel.arguments.parse_args()
     hotel = HotelModel.hotel_find_by_id(id)
     if hotel:
         hotel.update_hotel(**data)
         try:
             hotel.save_hotel()
         except:
             return {
                 'message': 'An internal error ocurred trying to save hotel'
             }, 500
         return hotel.json(), 200
     hotel = HotelModel(id, **data)
     try:
         hotel.save_hotel()
     except:
         return {
             'message': 'An internal error ocurred trying to save hotel'
         }, 500
     return hotel.json(), 201
Exemple #19
0
 def put(self, hotel_id):
     dados = Hotel.argumentos.parse_args(
     )  # ta pegando os dados atraves dos argumemtos passado
     #novo_hotel = { 'hotel_id': hotel_id, **dados} #ta criando um novo hotel, com a chave hotel_id e desembrulhando os dados
     hotel_encontrado = HotelModel.find_hotel(
         hotel_id
     )  #hotel é instaciado, e usa a função para encontrar o hotel
     if hotel_encontrado:
         hotel_encontrado.update_hotel(
             **dados)  #se eu encontrar o hotel eu faço uma atualizaçao
         hotel_encontrado.save_hotel()
         return hotel_encontrado.json(
         ), 200  # retorno o valor atualizado e um OK
     #hoteis.append(novo_hotel) #caso nao exista (caso o ID do hotell nao exista), eu crio um novo
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         {"message": "An internal error ocurred trying to save hotel."}, 500
     return hotel.json(), 201  #criado
Exemple #20
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}' already exists.".format(hotel_id)
            }, 400  #Bad Request

        dados = Hotel.atributos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

        if not SiteModel.find_by_id(dados['site_id']):
            return {
                'message': 'The hotel must be associated to a valid site id.'
            }, 400

        try:
            hotel.save_hotel()
        except:
            return {
                "message": "An error ocurred trying to create hotel."
            }, 500  #Internal Server Error
        return hotel.json(), 201
Exemple #21
0
    def post(hotel_id):  #creating a new hotel (register in website)
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": f"hotel {hotel_id} already exists."
            }, 400  #Bad Request

        data = Hotel.args.parse_args()
        hotel = HotelModel(hotel_id, **data)

        if not SiteModel.find_by_id(data.get("site_id")):
            return {
                "message": "the hotel must be associated with a valid site"
            }, 400
        try:
            hotel.save_hotel()
        except:
            traceback.print_exc()
            return {
                "message": "An error ocurred trying to create hotel."
            }, 500  #Internal Server Error
        return hotel.json(), 201
Exemple #22
0
    def post(self, hotel_id):
        # criar apenas se existir
        if HotelModel.find_hotel(hotel_id):
            return {
                'message': "Hotel id {} already exists.".format(hotel_id)
            }, 400  # Bad Request
        # captura atributos
        dados = self.argumentos.parse_args()

        ## TODO trocar aqui por um d_vector
        ## usar array.tobytes() e depois np.frombuffer(s)
        dados['audio'] = np.random.randn(10).tobytes()
        # instanciando  novo hotel
        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {
                'message': 'An internal error ocurred trying to save hotel.'
            }, 500  # Internal Server Error
        return hotel.json()
Exemple #23
0
 def put(self, hotel_id):
     """Se existe hotel cria se nao altera"""
     dados = self.argumentos.parse_args()  # captura os dados
     #modo antigo
     #novo_hotel = {'hotel_id': hotel_id, **dados} #** desempacota todos argumentos definidos no contrutor se for chave-valor
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     # existir update, se nao cria
     if hotel_encontrado:
         # apenas atualiza os dados, não o resto como o id
         hotel_encontrado.update_hotel(**dados)
         hotel_encontrado.save_hotel()  # salvar no banco
         return hotel_encontrado.json(), 200  # OK
     # Instancia novo objeto apenas se não encontrar
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         return {
             'message': 'An internal error ocurred trying to save hotel.'
         }, 500  # Internal Server Error
     return hotel.json(), 201  # criado
Exemple #24
0
 def put(self, hotel_id):
     dados = Hotel.argumentos.parse_args()
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     if hotel_encontrado:
         hotel_encontrado.update_hotel(**dados)
         try:
             hotel_encontrado.save_hotel()
         except:
             return {
                 'message':
                 'An internal error ocurred trying to save hotel.'
             }, 500
         return hotel_encontrado.json(), 200
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         return {
             'message': 'An internal error ocurred trying to save hotel.'
         }, 500  # código de erro interno do servidor
     return hotel.json(), 201  # código de que foi criado
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args(
        )  #transforma em chave e valor dos argumentos
        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            try:
                hotel_encontrado.save_hotel()
            except:
                return {
                    'message': 'Erro interno ao tentar salvar o hotel.'
                }, 500
            return hotel_encontrado.json(), 200  #OK

        #se nao for encontrado, criar
        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except:
            return {'message': 'Erro interno ao tentar salvar o hotel.'}, 500
        return hotel.json(), 201  #created (criado)
Exemple #26
0
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()

        # atualizar hotel se for encontrado
        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)

            try:
                hotel_encontrado.save_hotel()
                return hotel_encontrado.json(), 200
            except Exception as err:
                return {'message': f'Erro ao atualizar os dados {err}'}, 500

        # Salvar novo hotel
        hotel_new = HotelModel(hotel_id, **dados)
        try:
            hotel_new.save_hotel()
            return hotel_new.json(), 201
        except Exception as err:
            return {'message': f'Erro ao salvar os dados {err}'}, 500
Exemple #27
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}'already exists.".format(hotel_id)
            }, 400

        dados = Hotel.argumentos.parse_args()
        novo_hotel = HotelModel(hotel_id, **dados)

        if not SiteModel.find_by_id(dados['site_id']):
            return {
                "message": "The hotel must be associeted to a valid site ID"
            }, 400

        try:
            novo_hotel.save_hotel()
        except:
            return {
                'messege': 'An internal error ocorred trying to save hotel'
            }, 500  #internal server error

        return novo_hotel.json()
Exemple #28
0
    def put(self, hotel_id):
        dados = Hotel.arguments.parse_args()

        obj_hotel = HotelModel.find_hotel(hotel_id)
        if obj_hotel:
            obj_hotel.update_hotel(**dados)
            try:
                obj_hotel.save_hotel()
            except:
                return {
                    "message":
                    "An internal error ocurred trying to save hotel."
                }, 500
            return obj_hotel.toJson(), 200
        obj_hotel = HotelModel(hotel_id, **dados)
        try:
            obj_hotel.save_hotel()
        except:
            return {
                "message": "An internal error ocurred trying to save hotel."
            }, 500
        return obj_hotel.toJson(), 201
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}' already exists.".format(hotel_id)
            }, 400  #bad request

        dados = Hotel.argumentos.parse_args(
        )  #transforma em chave e valor dos argumentos
        hotel = HotelModel(hotel_id, **dados)  #criando objeto do tipo hotel

        if not SiteModel.find_by_id(dados['site_id']):
            return {
                'message': 'The Hotel must be associated to a valid site_id.'
            }, 400

        try:
            hotel.save_hotel()
        except:
            return {
                'message': 'Erro interno ao tentar salvar o hotel.'
            }, 500  #internal server error
        return hotel.json()
Exemple #30
0
    def put(self, hotel_id):
        dados = self.argumentos.parse_args()
        hotel_encontrado = HotelModel.find_hotel(hotel_id)

        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            try:
                hotel_encontrado.save_hotel()
            except:
                return {
                    'message':
                    'An internal error ocurred trying to save hotel.'
                }, 500
            return hotel_encontrado.json(), 200  # OK

        hotel_objeto = HotelModel(hotel_id, **dados)  # Objeto
        try:
            hotel_objeto.save_hotel()
        except:
            return {
                'message': 'An internal error ocurred trying to save hotel.'
            }, 500
        return hotel_objeto.json(), 201