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 get_reservation(reservation_id): reservation = ReservationManager.retrieve_by_id(reservation_id) if reservation is None: return jsonify({ 'message': 'No reservation for this id\n', 'status': 'Bad Request' }), 400 return jsonify({ 'status': 'Success', 'message': 'The reservation were correctly loaded', 'reservations': reservation.serialize() }), 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): """Allows the customer to edit a single reservation, if there's an available table within the opening hours of the restaurant. Linked to route reservation/{reservation_id} [PUT] Args: reservation_id (int): univocal identifier of the reservation restaurant_id (int): univocal identifier of the restaurant Returns: Invalid request for wrong data or if the reservation doesn't exists The json of the edited reservation """ try: json_data = request.get_json() start_time = json_data['start_time'] people_number = json_data['people_number'] tables = json_data['tables'] times = json_data['times'] old_reservation = ReservationManager.retrieve_by_id(reservation_id) user_id = old_reservation.user_id restaurant_id = old_reservation.restaurant_id ReservationManager.delete_reservation(old_reservation) table_id, start_time = validate_reservation(tables, times, start_time, people_number) if table_id is False: ReservationManager.create_reservation(old_reservation) raise ValueError reservation = Reservation(user_id, table_id, restaurant_id, people_number, start_time) ReservationManager.create_reservation(reservation) except Exception as e: print("MUSCAAAAAAAAA") return jsonify({ 'status': 'Bad request', 'message': 'The data provided were not correct.\n' + str(e) }), 400 return jsonify({ 'status': 'Success', 'message': 'Reservation succesfully added' }), 200
def reservation_details(restaurant_id, reservation_id): """ Given a restaurant, this method returns all its reservations Args: restaurant_id (int): univocal identifier of the restaurant reservation_id (int): univocal identifier of the reservations Returns: [type]: [description] """ reservation = ReservationManager.retrieve_by_id(reservation_id) user = CustomerManager.retrieve_by_id(reservation.user.id) table = reservation.table restaurant = reservation.restaurant return render_template("reservation_details.html", reservation=reservation, user=user, table=table, restaurant=restaurant)