def get_all_reservation_restaurant(restaurant_id): """Returns the whole list of reservations, given a restaurant. It also gives to the operator the opportunity to filter reservations by date, so it's possible to count people. Linked to route /reservation/restaurant/{restaurant_id} [GET] Args: restaurant_id (int): univocal identifier of the restaurant Returns: Invalid request if restaurant doesn't exists The list of json of the reservations. """ try: reservations = ReservationManager.retrieve_by_restaurant_id( restaurant_id) reservations = [ reservation.serialize() for reservation in reservations ] if not reservations: raise ValueError except Exception as e: return jsonify({ 'message': 'No reservation for this restaurant\n', 'status': 'Bad Request' }), 400 return jsonify({ 'status': 'Success', 'message': 'The reservations were correctly loaded', 'reservations': reservations }), 200
def reservation_all(restaurant_id): """Returns the whole list of reservations, given a restaurant. It also gives to the operator the opportunity to filter reservations by date, so it's possible to count people. Args: restaurant_id (int): univocal identifier of the restaurant Returns: The template of the reservations. """ filter_form = FilterForm() reservations = ReservationManager.retrieve_by_restaurant_id(restaurant_id) restaurant = RestaurantManager.retrieve_by_id(restaurant_id) people = 0 for r in reservations: if r.is_confirmed: people = people + r.people_number if request.method == 'POST': if filter_form.is_submitted(): filter_date = filter_form.data['filter_date'] start_time = filter_form.data['start_time'] end_time = filter_form.data['end_time'] if filter_date is not None and start_time is not None and end_time is not None: start_date_time = datetime.combine(filter_date, start_time) end_date_time = datetime.combine(filter_date, end_time) res = ReservationManager.retrieve_by_date_and_time( restaurant_id, start_date_time, end_date_time) people = 0 for r in res: if r.is_confirmed: people = people + r.people_number return render_template("restaurant_reservation.html", restaurant=restaurant, reservations=res, filter_form=filter_form, people=people) else: flash("The form is not correct") reservations.sort(key=lambda reservation: reservation.start_time) return render_template("restaurant_reservation.html", restaurant=restaurant, reservations=reservations, filter_form=filter_form, people=people)