def confirm_reservation(reservation_id): """ This method is used to confirm reservation Linked to route /reservation/confirm/{reservation_id} [PUT] Args: reservation_id (Integer): the restaurant id of the reservation restaurant_id (Integer): univocal identifier of the restaurant Returns: Invalid request if the reservation doesn't exists A success message """ reservation = ReservationManager.retrieve_by_id(reservation_id) if reservation is None: return jsonify({ 'status': 'Bad Request', 'message': 'There is not reservation with this id' }), 400 reservation.set_is_confirmed() ReservationManager.update_reservation(reservation) return jsonify({ 'status': 'Success', 'message': 'Reservation succesfully confirmed' }), 200
def confirm_reservation(res_id): """ This method is used to confirm reservation Args: res_id (Integer): the restaurant id of the reservation Returns: redirect: redirects to the reservations operator page """ reservation = ReservationManager.retrieve_by_id(res_id) reservation.set_is_confirmed() ReservationManager.update_reservation(reservation) return redirect(url_for('reservation.my_reservations'))
def edit_reservation(reservation_id, customer_id): """Allows the customer to edit a single reservation, if there's an available table within the opening hours of the restaurant. Args: reservation_id (int): univocal identifier of the reservation customer_id (int): univocal identifier of the customer Returns: Redirects the view to the customer profile page. """ form = ReservationForm() reservation = ReservationManager.retrieve_by_customer_id( user_id=customer_id)[0] restaurant = RestaurantManager.retrieve_by_id(reservation.restaurant_id) if request.method == 'POST': if form.validate_on_submit(): start_date = form.data['start_date'] start_time = form.data['start_time'] people_number = form.data['people_number'] start_time_merged = datetime.combine(start_date, start_time) table = validate_reservation(restaurant, start_time_merged, people_number) if table != False: reservation.set_people_number(people_number) reservation.set_start_time(start_time_merged) reservation.set_table(table) ReservationManager.update_reservation(reservation) else: flash( "There aren't free tables for that hour or the restaurant is closed" ) else: flash("The form is not correct") return redirect(url_for('auth.profile', id=customer_id))