use rocket::{ form::Form, get, post, response::{Flash, Redirect}, routes, FromForm, Route, State, }; use sqlx::SqlitePool; use crate::model::{planned_event::PlannedEvent, tripdetails::TripDetails, user::AdminUser}; //TODO: add constraints (e.g. planned_amount_cox > 0) #[derive(FromForm)] struct AddPlannedEventForm { day: String, name: String, planned_amount_cox: i32, allow_guests: bool, planned_starting_time: String, max_people: i32, notes: Option, } #[post("/planned-event", data = "")] async fn create( db: &State, data: Form, _admin: AdminUser, ) -> Flash { //TODO: fix clones() let trip_details_id = TripDetails::new( db, data.planned_starting_time.clone(), data.max_people, data.day.clone(), data.notes.clone(), ) .await; //TODO: fix clone() PlannedEvent::new( db, data.name.clone(), data.planned_amount_cox, data.allow_guests, trip_details_id, ) .await; Flash::success(Redirect::to("/"), "Successfully planned the event") } #[get("/planned-event//delete")] async fn delete(db: &State, id: i64, _admin: AdminUser) -> Flash { PlannedEvent::delete(db, id).await; Flash::success(Redirect::to("/"), "Successfully deleted the event") } pub fn routes() -> Vec { routes![create, delete] }