def post(self): # create a new restaurant data = self.parser.parse_args() if RestaurantModel.find_by_name(data['name']): return {'message': ALREADY_EXISTS_ERROR.format(data['name'])}, 400 # else try to create new restaurant if data['isOpen'] is None: data['isOpen'] = True # open by default # if data['logo'] is None: # data['logo'] = default_logo_url res = RestaurantModel(None, **data) try: res.save_to_db() except: traceback.print_exc() return { 'message': INTERNAL_ERROR.format('Failed to create restaurant.') }, 500 return res.json(), 201
def get(self, name): restaurant = RestaurantModel.find_by_name(name) if restaurant: return restaurant.to_json() return {'message': 'Restaurant not registered'}, 404