Esempio n. 1
0
    def post(self, hotel_id):
        """
        Cria hotel
        """
        if HotelModel.find_hotel(hotel_id):
            # bad request
            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.get('site_id')):
            return {
                'message': 'The hotel must be associated to a valid site id.'
            }, 400

        try:
            hotel.save_hotel()
        except expression as identifier:
            return {
                'message':
                'An internal server error occured trying to save hotel.'
            }

        return hotel.json()
Esempio n. 2
0
 def get(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     return {
         'message': 'Hotel not found.'
     }, 404  # código de not found (404)
Esempio n. 3
0
    def get(self, hotel_id):
        hotel = HotelModel.find_hotel(hotel_id)

        if hotel is not None:
            return hotel.json()

        return {'message': 'Hotel not found'}, 404  # not found
Esempio n. 4
0
    def put(self, hotel_id):
        """
        Alterar Hotel
        """
        dados = Hotel.argumentos.parse_args()

        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            hotel_encontrado.update_hotel(**dados)
            try:
                hotel.save_hotel()
            except expression as identifier:
                return {
                    'message':
                    'An internal server error occured trying to save hotel.'
                }
            return novo_encontrado.json(), 200  # updated

        hotel = HotelModel(hotel_id, **dados)
        try:
            hotel.save_hotel()
        except expression as identifier:
            return {
                'message':
                'An internal server error occured trying to save hotel.'
            }
        return hotel.json(), 201  # created
Esempio n. 5
0
    def post(self, hotel_id):

        dados = self.argumentos.parse_args()

        if HotelModel.find_hotel(
                hotel_id) and HotelModel.find_hotel_by_site_id(
                    dados.get('site_id')):
            return {
                'message': f"Hotel id '{hotel_id}' already exists."
            }, 400  #bad request

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

        try:
            nome = dados.get('nome').strip()
        except:
            nome = None

        if not nome:
            return {'message': 'The field name cannot be blank or null'}

        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()
Esempio n. 6
0
 def get(hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     return {
         "message": f"hotel '{hotel_id}' not found."
     }, 404  #error status code, not found
 def post(self, hotel_id):
     if HotelModel.find_hotel(hotel_id):
         return {
             "message": "Hotel id '{}' already exists.".format(hotel_id)
         }, 400
     dados = Hotel.atributos.parse_args()
     hotel = (HotelModel(hotel_id, **dados))
     if not SiteModel.find_by_id(dados.get('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 ocurred trying to save hotel.'
         }, 500
     # novo_hotel = hotel_objeto.json()
     # novo_hotel = {
     #     'hotel_id': hotel_id,
     #     'nome': dados['nome'],
     #     'estrelas': dados['estrelas'],
     #     'diaria': dados['diaria'],
     #     'cidade': dados['cidade']
     # } # igual novo_hotel = { 'hotel_id': hotel_id, **dados }
     # hoteis.append(novo_hotel)
     return hotel.json(), 200
Esempio n. 8
0
 def put(self, hotel_id):
     #parse dos objetos passados pra classe
     dados = Hotel.argumentos.parse_args()
     #procura no bd o hotel
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     if hotel_encontrado:
         #Se encontrado, update
         hotel_encontrado.update_hotel(**dados)
         try:
             #salva o update no bd
             hotel_encontrado.save_hotel()
         except:
             return {
                 'message':
                 'An internal error ocurred trying to save hotel.'
             }, 500  #intel server error
         return hotel_encontrado.json(), 200
     #caso hotel não tenha sido encontrado, salva um novo
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         return {
             'message': 'An internal error ocurred trying to save hotel.'
         }, 500  #intel server error
     return hotel.json(), 201  # created
Esempio n. 9
0
    def get(self, hotel_id):
        hotel = HotelModel.find_hotel(hotel_id)
        if hotel:
            return hotel.json()

        # status: not found
        return {'msg': f'Hotel {hotel_id} não encontrado!'}, 404
Esempio n. 10
0
 def get(self, hotel_id):
     """
     Retorna Hotel
     """
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     return {'message': 'hotel not found'}, 404  # not found
Esempio n. 11
0
 def get(self, hotel_id):
     # hotel = Hotel.find_hotel(hotel_id)
     hotel = HotelModel.find_hotel(hotel_id)
     # if hotel:
     #     return hotel
     if hotel:
         return hotel.json()
     return {'message': 'Hotel not found.'}, 404
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except:
             return {'Message':'Erro ao excluir do banco de dados.'}
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel not found.'}, 404
Esempio n. 13
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.save_hotel()
         except:
             return {'message': 'An internal error ocured trying to save hotel.'}, 500
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel not found'}, 404
Esempio n. 14
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except:
             return {'message': 'Internal Server Error ocurred trying to delete hotel'}, 500
         return {'message': 'Hotel deleted!'}
     return {'message': 'Hotel not found'}
Esempio n. 15
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except:
             return {'message': 'An error occurred trying to delete hotel.'}, 500
         return {'message': 'Hotel deleted.'}
     return {"message": "Hotel not found.".format(hotel_id)}, 404
Esempio n. 16
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except: 
             return {'message': 'An internal error ocurred trying to delete hotel.'}, 500 #internal server error 
         return {'message':'Hotel deleted.'}
     return {'message:': 'Hotel not found.'},404
Esempio n. 17
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
             return {"message": "Deleted !"}
         except:
             return {"message": "Fail to delete"}, 500
     return {"message": "Not found !"}
Esempio n. 18
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except InternalError:
             return {"message": "An internal error occurred"}, 500
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel not found.'}, 404
Esempio n. 19
0
 def get(self, hotel_id):
     hotel = HotelModel.find_hotel(
         hotel_id)  #ele usa a funçao para retornar o hotel
     #variavel hotel, é instanciada, chamo a classe HotelModel, e chamo a funçaõ find_hotel, e passo o id do hotel
     if hotel:  #caso encontre ele retorna o hotel
         return hotel.json()
     return {
         'message': 'Hotel not found'
     }  # retorna que o Hotel nao foi encontrado
Esempio n. 20
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel is None:
         return errors._NOT_FOUND, server_code.NOT_FOUND
     try:
         hotel.delete_hotel()
     except:
         return errors._DELETE_ERROR, server_code.INTERNAL_SERVER_ERROR
     return success._DELETED, server_code.OK
Esempio n. 21
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except:
             return {'message': 'erro encontrado'}, 500
         return {'message': 'hotel deleted'}, 201
     return {'message': 'Hotel not found'}, 404
Esempio n. 22
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except:
             return {'message': 'Internal error'}, 500
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel not found.'}, 404
Esempio n. 23
0
    def delete(self, hotel_id: int):
        hotel = HotelModel.find_hotel(hotel_id)
        if hotel is None:
            return {'message': 'The Hotel doesn\'t exist'}, 404

        try:
            hotel.delete()
        except:
            return {'message': 'An internal server error'}, 500
        return 200
Esempio n. 24
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()
Esempio n. 25
0
    def delete(self, hotel_id):
        hotel = HotelModel.find_hotel(hotel_id)

        if hotel:
            try:
                hotel.delete_hotel()
            except:
                return {'message': 'Internal Error while tring to delete'}, 500
            return {'message': 'Hotel Deleted'}, 200
        return {'message': 'Hotel not found'}, 400
Esempio n. 26
0
    def delete(self, hotel_id):
        hotel = HotelModel.find_hotel(hotel_id)
        if hotel:
            try:
                hotel.delete_hotel()
                return {'message': f"Hotel '{hotel_id}' deleted."}
            except Exception as err:
                return {'message': f'Erro ao Deletar os dados {err}'}

        return {'message': f"Hotel '{hotel_id}' not found."}, 404
Esempio n. 27
0
    def get(self, hotel_id: int) -> dict:
        hotel = HotelModel.find_hotel(hotel_id)

        if hotel:
            return {
                'message': f'Hotel {hotel_id} found.',
                'data': hotel.json()
            }, 200

        return {'message': 'Hotel not found.', 'data': {}}, 404
Esempio n. 28
0
 def delete(self, hotel_id):
     global hoteis
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
         except Exception:
             return {'message', 'An error occurred trying to delete'}
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel not found'}, 404
Esempio n. 29
0
    def delete(self, hotel_id):
        hotel = HotelModel.find_hotel(hotel_id)

        if hotel:
            try:
                hotel.delete_hotel()
            except:
                return {'message': 'internal server error'}, 500
            return {'message': 'hotel deletado'}
        return {'message': 'hotel não encotrado'}, 404
Esempio n. 30
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {
                "message": "Hotel id '{}' already exists.".format(hotel_id)
            }, 200

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