def post(self):
     data = Hotel.arguments.parse_args()
     hotel = HotelModel(**data)
     if HotelModel.hotel_find_by_name(hotel.name):
         return {'message': 'Hotel already exists'}, 400
     if SiteModel.find_site_by_id(hotel.site_id) is None:
         return {'message': 'Site not exists'}, 400
     try:
         hotel.save_hotel()
     except:
         return {
             'message': 'An internal error ocurred trying to save hotel'
         }, 500
     return hotel.json(), 201
示例#2
0
 def get(self, id):
     site = SiteModel.find_site_by_id(id)
     if site:
         return site.json()
     return {'message': 'Site not found'}, 404
示例#3
0
 def delete(self, id):
     site = SiteModel.find_site_by_id(id)
     if site:
         site.delete_site()
         return {'message': 'Site deleted'}, 204
     return {'message': 'Site not found'}, 404