def get(self, hotel_id):

        hotel = HotelModel.find_hotel(hotel_id)

        if hotel:
            return hotel.json()

        return {"message": "Hotel not found"}, 404
Example #2
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         try:
             hotel.delete_hotel()
             return {'message': 'Hotel deletado com sucesso'}, 200
         except:
             return {'message': 'Erro interno ao deletar'}, 500
         return {'message': 'Not Found'}, 400
Example #3
0
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()

        hotel_encontrado = HotelModel.find_hotel(hotel_id)
        if hotel_encontrado:
            try:
                hotel_encontrado.update_hotel(**dados)
            except:
                return {'message': 'Erro interno ao alterar'}, 500
            return hotel_encontrado.json(), 200
        return {'message': 'hotel não encontrado'}, 404
Example #4
0
 def post(self, hotel_id):
     if HotelModel.find_hotel(hotel_id):
         return {'message': 'hotel {} alread exist'.format(hotel_id)}, 400
     dados = Hotel.argumentos.parse_args()
     hotel = HotelModel(hotel_id, **dados)
     hotel.save_hotel()
     return hotel.json()
    def delete(self, hotel_id):

        hotel = HotelModel.find_hotel(hotel_id)

        if hotel:
            try:
                hotel.delete_hotel()

            except:
                return {"message": "error"}, 500

            return {"message": "hotel deleted"}

        return {"message": "hotel not found "}
Example #6
0
 def post(self, hotel_id):
     if HotelModel.find_hotel(hotel_id):
         return {
             'message': 'Hotel id "{}" alread exists'.format(hotel_id)
         }, 400
     dados = Hotel.atributos.parse_args()
     hotel = HotelModel(hotel_id, **dados)
     hotel.save_hotel()
     return hotel.json()
 def post(self, hotel_id):
     if HotelModel.find_hotel(hotel_id):
         return {'message':'Hotel id "{}" alread exists'.format(hotel_id)}, 400
     dados = Hotel.atributos.parse_args()
     hotel=  HotelModel(hotel_id, **dados)
     if not SiteModel.find_by_id(dados['site_id']):
         return {'message': 'o hotel precisa estar associado a um site, o site nao é valido'}
     hotel.save_hotel()
     return hotel.json()
 def put(self, hotel_id):
     dados = Hotel.atributos.parse_args()
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     if hotel_encontrado:
         hotel_encontrado.update(**dados)
         hotel_encontrado.save_hotel()
         return hotel_encontrado.json(), 200
     hotel= HotelModel(hotel_id, **dados)
     hotel.save_hotel()
     return hotel.json(),201
Example #9
0
 def put(self, hotel_id):
     dados = Hotel.argumentos.parse_args()
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         hotel.update_hotel(**dados)
         hotel.save_hotel()
         return hotel.json(), 200
     hotel = HotelModel(hotel_id, **dados)
     hotel.save_hotel()
     return hotel.json(), 201
Example #10
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(**dados)

        try:
            hotel.save_hotel()

        except:
            return {"message": "error"}, 500

        return hotel.json()
Example #11
0
    def post(self, hotel_id):

        if HotelModel.find_hotel(hotel_id):
            return {"message": "Hotel ID '{}' ja existe".format(hotel_id)}, 400
        else:
            dados = Hotel.argumentos.parse_args()
            # Desempacotando dados como kwards
            hotel = HotelModel(hotel_id, **dados)

            if not SiteModel.find_by_id(dados.get('site_id')):
                return {
                    'message': 'O Hotel precisa estar assciado a um id valido'
                }, 400
            try:
                hotel.save_hotel()
            except:
                return {'message': 'Erro interno ao salvar Hotel'}, 500
            return hotel.json(), 201
Example #12
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['nome'])
            hotel_encontrado.save_hotel()
            return hotel_encontrado.json(), 200

        hotel = HotelModel(**dados)

        try:
            hotel.save_hotel()

        except:
            return {"message": "error"}, 500

        return hotel.json(), 201
 def get(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     return {'message': 'hotel nao achado'}, 404
 def delete(self, hotel_id):
     hotel_encontrado = HotelModel.find_hotel(hotel_id)
     if hotel_encontrado:
         hotel_encontrado.delete()
         return {'message': 'Hotel deleted.'}
     return {'message': 'Hotel nao achado.'}
Example #15
0
 def delete(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         hotel.delete_hotel()
         return {'message': 'hotel {} deleted'.format(hotel_id)}
     return {'message': 'hotel not found'}
Example #16
0
 def get(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     return {'message': 'Hotel não econtrado'}
Example #17
0
 def get(self, hotel_id):
     hotel = HotelModel.find_hotel(hotel_id)
     if hotel:
         return hotel.json()
     else:
         return {'message': 'hotel not found'}, 404
Example #18
0
 def post(self):
     data = arguments.parse_args()
     hotel = HotelModel(**data)
     hotel.save()
     return hotel.json(), 201
Example #19
0
 def delete(self, id):
     hotel = HotelModel.findExists(id)
     hotel.delete()
     return {}, 204
Example #20
0
 def put(self, id):
     saved_hotel = HotelModel.findExists(id)
     data = arguments.parse_args()
     saved_hotel.update(**data)
     saved_hotel.save()
     return saved_hotel.json(), 200
Example #21
0
 def get(self, id):
     hotel = HotelModel.findById(id)
     if hotel:
         return hotel.json()
     raise NotFound('Hotel not found')