コード例 #1
0
    def post(self, hotel_id):

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

        hoteis.append(hotel.json())

        return hotel.json(), 200
コード例 #2
0
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

        hoteis.append(hotel.json())

        if Hotel.find_hotel(hotel_id):
            Hotel.find_hotel(hotel_id).update(hotel.json())
            return hotel.json(), 200

        hoteis.append(hotel.json())
        return hotel.json(), 201
コード例 #3
0
 def post(self, hotel_id):
     dados = Hotel.argumentos.parse_args(
     )  #Coletar os dados passados no corpo da requisição
     hotel_objeto = HotelModel(hotel_id, **dados)
     novo_hotel = hotel_objeto.json()
     hoteis.append(novo_hotel)
     return novo_hotel, 200  #Código de Sucesso
コード例 #4
0
    def post(self, hotel_id):

        dados = Hotel.argumentos.parse_args()
        hotel_objeto = HotelModel(hotel_id, **dados)
        novo_hotel = hotel_objeto.json()
        hoteis.append(novo_hotel)
        return novo_hotel, 200
コード例 #5
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
コード例 #6
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()
コード例 #7
0
 def post(self, hotel_id):
   data_arguments = Hotel.arguments.parse_args()
   hotel_obj = HotelModel(hotel_id, **data_arguments)
   new_hotel = hotel_obj.json()
   hotels.append(new_hotel)
   
   return new_hotel, 201
コード例 #8
0
ファイル: hotel.py プロジェクト: joaoo-vittor/estudo-python
    def post(self, hotel_id):
        dados = self.argumentos.parse_args()
        obj_hotel = HotelModel(hotel_id, **dados)
        novo_hotel = obj_hotel.json()
        hoteis.append(novo_hotel)

        return novo_hotel, 200  # status: success
コード例 #9
0
    def post(self, hotel_id):
        data = self.args.parse_args()
        hotel_obj = HotelModel(int(hotel_id), **data)
        updated_hotel = hotel_obj.json()
        HOTELS.append(updated_hotel)

        return updated_hotel, 200
コード例 #10
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
コード例 #11
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()
コード例 #12
0
 def put(self, hotel_id):
     dados = Hotel.atributos.parse_args()
     hotel_objeto = HotelModel(hotel_id, **dados)
     novo_hotel = hotel_objeto.json()
     hotel = Hotel.find_hotel(hotel_id)
     if hotel:
         hotel.update(novo_hotel)
         return hotel, 200
     hoteis.append(novo_hotel)
     return novo_hotel, 201
コード例 #13
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()
コード例 #14
0
 def post(self, id):
     body = reqparse.RequestParser()
     body.add_argument("name")
     body.add_argument("starts")
     body.add_argument("city")
     dados = body.parse_args()
     hotel_obj = HotelModel(id, **dados)
     new_hotel = hotel_obj.json()
     hoteis.append(new_hotel)
     return new_hotel
コード例 #15
0
ファイル: hotel.py プロジェクト: adniltonsantos/python
    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()
コード例 #16
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)
        try:
            hotel.save_hotel()
        except:
            return {"message": "An error ocurred trying to create hotel."}, 500 #Internal Server Error
        return hotel.json(), 201
コード例 #17
0
    def post(self, hotel_id):

        hotel_id = len(Hotel.db['hoteis']) + 1
        dados = Hotel.argumentos.parse_args()
        hto = HotelModel(hotel_id, **dados)
        novo_hotel = hto.json()
        if hotel_id != Hotel.db['id']:
            Hotel.db['hoteis'].append(novo_hotel)
            DB.save(Hotel.db)
            return novo_hotel, 200
        return {'message': str(hotel_id) + 'existing'}
コード例 #18
0
    def put(self, hotel_id):
        data = self.args.parse_args()
        hotel_obj = HotelModel(int(hotel_id), **data)
        updated_hotel = hotel_obj.json()

        hotel = self.find_hotel_by_id(hotel_id)
        if hotel:
            hotel.update(updated_hotel)
            return updated_hotel, 200
        HOTELS.append(updated_hotel)
        return updated_hotel, 201
コード例 #19
0
  def post(self, id):


    #chaves e valores de todos os argumentos passados
    dados = Hotel.argumentos.parse_args()

    obj_hotel =HotelModel(id= f'{uuid.uuid4()}' , **dados)
    novo_hotel = obj_hotel.json()

    hoteis.append(novo_hotel)
    return novo_hotel, 201
コード例 #20
0
    def put(self, hotel_id):
        dados = Hotel.atributos.parse_args()
        hotel = HotelModel(hotel_id, **dados)

        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.save_hotel()
        return hotel.json(), 201
コード例 #21
0
    def put(self, hotel_id):
        dados = self.argumentos.parse_args()

        _novo_hotel = HotelModel(hotel_id, **dados)
        novo_hotel = _novo_hotel.json()
        hotel = self.find_hotel(hotel_id)
        if hotel:
            hotel.update(novo_hotel)
            return novo_hotel, 200
        hoteis.append(novo_hotel)
        return novo_hotel, 201
コード例 #22
0
    def post(self, hotel_id):
        if HotelModel.find_hotel(hotel_id):
            return {"message": "Hotel '{}' already exists.".format(hotel_id)}, 400 #bad request

        data = Hotel.arguments.parse_args()
        new_hotel_object = HotelModel(hotel_id, **data)
        new_hotel = new_hotel_object.json()
        try:
            hotel.save_hotel()
        except: 
            return {'message': 'An internal error ocurred trying to save hotel.'}, 500 #internal server error 
        return hotel.json(), 200
コード例 #23
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)
		try:
			hotel.save_hotel()
		except:
			return {'message': 'An internal error ocurred when trying to save hotel.'}, 500 # server internal error
		return hotel.json()
コード例 #24
0
ファイル: hotel.py プロジェクト: Alexvjunior/ApiRestful
 def put(self, hotel_id):
     dados = self.argumentos.parse_args()
     hotel_found = HotelModel.find_hotel(hotel_id)
     if hotel_found is not None:
         hotel_found.update_hotel(**dados)
         return hotel_found.json(), server_code.OK
     hotel = HotelModel(hotel_id, **dados)
     try:
         hotel.save_hotel()
     except:
         return errors._SAVE_ERROR, server_code.INTERNAL_SERVER_ERROR
     return hotel.json(), server_code.CREATED
コード例 #25
0
ファイル: hotel.py プロジェクト: Alexvjunior/ApiRestful
 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
コード例 #26
0
ファイル: hotel.py プロジェクト: adniltonsantos/python
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()  #pegandos

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

        hotel = HotelModel(hotel_id, **dados)
        hotel.save_hotel()
        return hotel.json(), 201
コード例 #27
0
  def put(self, hotel_id):
    
    data_arguments = Hotel.arguments.parse_args()
    hotel_obj = HotelModel(hotel_id, **data_arguments)
    new_hotel = hotel_obj.json()
    hotel = Hotel.find_hotel(hotel_id)

    if hotel:
      hotel.update(new_hotel)
      return new_hotel, 200
    hotels.append(new_hotel)
    return new_hotel, 201
コード例 #28
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)
     try:
         hotel.save_hotel()
     except Exception:
         return {'message': 'An error occurred trying to save hotel.'}, 500
     return hotel.json()
コード例 #29
0
ファイル: hotel.py プロジェクト: gabriel-correia0408/RestApi
    def put(self, hotel_id):
        dados = Hotel.argumentos.parse_args()
        hotel_objto = HotelModel(hotel_id, **dados)
        novo_hotel = hotel_objto.json()
        hotel = Hotel.encontrar_hotel(hotel_id)
        if hotel:
            hotel.update(novo_hotel)
            return novo_hotel, 200 # tudo ok
        hoteis.append(novo_hotel)
        return novo_hotel, 201 #criado

        pass
コード例 #30
0
    def put(self, hotel_id):

        dados = Hotel.argumentos.parse_args()
        hto = HotelModel(hotel_id, **dados)
        novo_hotel = hto.json()
        hotel = Hotel.find(hotel_id)
        if hotel:
            hotel.update(novo_hotel)
            Hotel.db['hoteis'].append(hotel)
            DB.save(Hotel.db)
            return novo_hotel, 200
        return {'message': 'Hotel not found'}, 404