예제 #1
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()
예제 #2
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()
예제 #3
0
 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
예제 #4
0
 def get(self, id=None, name=None):
     if id:
         site = SiteModel.find_by_id(id)
     else:
         site = SiteModel.find_by_name(name)
     if site:
         return site.json()
     return {'message': 'Site not found'}, 404
예제 #5
0
    def delete(self, id=None, name=None):
        if id:
            site = SiteModel.find_by_id(id)
        else:
            site = SiteModel.find_by_name(name)
        if site:
            site.delete_from_db()

        return {'message': 'Site deleted'}
예제 #6
0
    def delete(self, site_id: int) -> dict:
        site = SiteModel.find_by_id(site_id)

        if site:
            try:
                site.delete_site()
                return {'message': f'User {site_id} has been deleted with success!', 'data': site.json()}, 200
            except Exception as ex:
                return {'message': f'An error ocurred when trying to delete site: {ex}'}, 500

        return {'message': 'Site not found.', 'data': {}}, 404
예제 #7
0
 def put(self, id):
     dados = Site.arguments.parse_args()
     site = SiteModel.find_by_id(id)
     if site:
         site.update_site(dados.nome_site, dados.tpo_site, dados.bloqueio)
         try:
             site.save_site()
             site.atualiza_txt()
             return {'message': 'Site alterada com sucesso'}, 200
         except Exception as ex:
             return {'message': str(ex)}, 500
     return {'message': 'Site não existe'}, 404
예제 #8
0
 def post(self, hotel_id):
     if HotelModel.find_hotel(hotel_id):
         return errors._EXISTENT, server_code.BAD_REQUEST
     dados = self.argumentos.parse_args()
     hotel = HotelModel(hotel_id, **dados)
     if SiteModel.find_by_id(hotel.site_id) is None:
         return errors._NOT_FOUND, server_code.NOT_FOUND
     try:
         hotel.save_hotel()
     except:
         return errors._SAVE_ERROR, server_code.INTERNAL_SERVER_ERROR
     return hotel.json(), server_code.OK
예제 #9
0
    def put(self, id):
        data = Site.parser.parse_args()
        site = SiteModel.find_by_id(id)
        current_user = current_identity.id

        if site:
            site.name = data['name']
            site.admin = current_user
        else:
            site = SiteModel(name=data['name'], admin=current_user)

        site.save_to_db()
        return site.json()
예제 #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.arguments.parse_args()
        object_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:
            object_hotel.save_hotel()
        except:
            return {'message': 'Internal Server Error ocurred trying to save hotel'}, 500
        return object_hotel.json(), 200
예제 #11
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.argumentos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

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

        try:
            hotel.save_hotel()
        except:
            {'message': 'An error ocurred trying to save hotel.'}, 500 # Internal Server Error
        return hotel.json()
예제 #12
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
예제 #13
0
    def post(self, hotel_id):
        # Cerificando se o id do hotel existe
        if HotelModel.find_hotel(hotel_id):
            return {'message': f'hotel id >{hotel_id}< already exists'}, 400  # bed requets

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

        if not SiteModel.find_by_id(dados.get('site_id')):
            return {"message": 'O hotel precisa estar associado a um site'}
        try:
            hotel_obj.save_hotel()
            return hotel_obj.json()
        except Exception as err:
            return {'message': f'Erro ao salvar os dados {err}'}
예제 #14
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)

        if not SiteModel.find_by_id(dados['site_id']):
            return {"The hotel must be associated to a valid site id."}, 400
        try:
            hotel.save_hotel()
        except:
            return {"message": "An error occured trying to save hotel."}, 500
        return hotel.json()
예제 #15
0
    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()
예제 #16
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
예제 #17
0
    def post(self) -> dict:
        data = getInformations()

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

        hotel = HotelModel(**data)

        try:
            hotel_id = hotel.save_hotel()
            return {
                'message': f'Hotel {hotel_id} create with success!',
                'data': hotel.json()
            }, 201
        except Exception as ex:
            return {
                'message':
                f'An error ocurred when trying to create hotel: {ex}'
            }, 500
예제 #18
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
예제 #19
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.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()
예제 #20
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()
예제 #21
0
    def post(self, camp_id):
        if CampeonatoModel.find_campeonato(camp_id):
            return {
                "message": "Campeonato id '{}' already exists.".format(camp_id)
            }, 400  #Bad Request

        dados = Campeonato.atributos.parse_args()
        campeonato = CampeonatoModel(camp_id, **dados)

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

        try:
            campeonato.save_campeonato()
        except:
            return {
                "message": "An error ocurred trying to create campeonato."
            }, 500  #Internal Server Error
        return campeonato.json(), 201
예제 #22
0
    def post(seidlf, id):
        if HotelModel.find(id):
            return {"message": "Hotel id '{}' already exists.".format(id)}, 400

        dados = Hotel.argumentos.parse_args()
        novo_hotel = HotelModel(
            id, **dados
        )  #implementando o **kwargs, distribuindo as propriedades de chave e valor pelo objeto

        if not SiteModel.find_by_id(novo_hotel.site_id):
            return {
                "message":
                "Site id '{}' not exists.".format(novo_hotel.site_id)
            }, 400

        try:
            novo_hotel.save()
        except Exception as e:
            return {
                "message": "An internal error ocurred trying to save 'hotel'."
            }, 500

        return novo_hotel.json(), 201
예제 #23
0
    def post(self, hotel_id):  # -----------------------Post
        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['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
        return hotel.json()
예제 #24
0
    def put(self, hotel_id: int) -> dict:
        data = getInformations()

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

        wanted_hotel = HotelModel.find_hotel(hotel_id)

        if wanted_hotel:
            try:
                wanted_hotel.update_hotel(**data)
                wanted_hotel.save_hotel()
                return {
                    'message': f'Hotel {hotel_id} updated with success',
                    'data': wanted_hotel.json()
                }, 200
            except Exception as ex:
                return {
                    'message':
                    f'An error ocurred when trying to update hotel: {ex}'
                }, 500

        try:
            hotel = HotelModel(**data)
            hotel.save_hotel()
            return {
                'message': f'Hotel {hotel_id} created with success',
                'data': hotel.json()
            }, 201
        except Exception as ex:
            return {
                'message':
                f'An error ocurred when trying to create hotel: {ex}'
            }, 500
예제 #25
0
 def get(self, id):
     site = SiteModel.find_by_id(id)
     if site:
         return site.json()
     return {"message": "Site não Encontrado!"}, 404
예제 #26
0
 def delete(self, id):
     site = SiteModel.find_by_id(id)
     site.atualiza_txt()