def get_random_reviews(restaurant_id, number): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 reviews = RestaurantService.get_reviews_random(restaurant_id, number) return list_obj_json("Reviews", reviews)
def get_photos(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 photos = RestaurantService.get_photos(restaurant_id) return list_obj_json("photos", photos)
def get_tables(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 tables = RestaurantService.get_tables(restaurant_id) return list_obj_json("tables", tables)
def get_openings(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 openings = RestaurantService.get_openings(restaurant_id) return list_obj_json("openings", openings)
def delete_restaurant(restaurant_id): if restaurant_id is None: return error_message("400", "restaurant_id not specified"), 400 restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 RestaurantService.delete_restaurant(restaurant_id) return _get_response("OK", 200)
def create_dish(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 body = request.get_json() dish = RestaurantService.create_dish(body["name"], body["price"], restaurant_id) return serialize(dish), 201
def create_table(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 body = request.get_json() table = RestaurantService.create_table(body["name"], body["max_seats"], restaurant_id) return serialize(table), 201
def create_review(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 body = request.get_json() review = RestaurantService.create_review(body["review"], body["stars"], body["reviewer_email"], restaurant_id) return serialize(review), 201
def create_photo(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 body = request.get_json() photo = RestaurantService.get_photo_with_url(body["url"]) if len(photo) != 0: return error_message("409", "URL already present"), 409 photo = RestaurantService.create_restaurant_photo(body["url"], body["caption"], restaurant_id) return serialize(photo), 201
def get_table(table_id): if table_id is None: return error_message("400", "table not specified"), 400 table = RestaurantService.get_table(table_id) if table is None: return error_message("404", "Table not found"), 404 restaurant = RestaurantService.get_restaurant(table.restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 total_table = { "name": table.name, "max_seats": table.max_seats, "available": table.available, "id": table.id, "restaurant": serialize(restaurant) } return total_table
def get_menus(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 menus = RestaurantService.get_menus(restaurant_id) all_menus = [] # get menu photos for each menu for menu in menus: photos = RestaurantService.get_menu_photos(menu.id) json_menu = serialize(menu) photos_list = [] for photo in photos: photos_list.append(serialize(photo)) json_menu["photos"] = photos_list all_menus.append(json_menu) return json.loads(json.dumps({"menus": all_menus}))
def get_restaurant_more_info(restaurant_id): # get restaurant and check if restaurant exists restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 info = dict() info["Restaurant"] = serialize(restaurant) # get menus menus = RestaurantService.get_menus(restaurant_id) all_menus = [] # get menu photos for each menu for menu in menus: photos = RestaurantService.get_menu_photos(menu.id) json_menu = serialize(menu) photos_list = [] for photo in photos: photos_list.append(serialize(photo)) json_menu["photos"] = photos_list all_menus.append(json_menu) info["Menus"] = all_menus # get photos about restaurant photos = RestaurantService.get_photos(restaurant_id) info["Photos"] = list_obj_json("", photos) # get dishes dishes = RestaurantService.get_dishes(restaurant_id) info["Dishes"] = list_obj_json("", dishes) # get openings openings = RestaurantService.get_openings(restaurant_id) info["Openings"] = list_obj_json("", openings) return json.loads(json.dumps({"Restaurant_info": info}))
def get_restaurant_name(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 else: return _get_response(restaurant.name, 200)
def get_restaurant(restaurant_id): restaurant = RestaurantService.get_restaurant(restaurant_id) if restaurant is None: return error_message("404", "Restaurant not found"), 404 else: return serialize(restaurant)