allow cox to edit own trips
This commit is contained in:
@ -7,7 +7,7 @@ use rocket::{
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
trip::{CoxHelpError, Trip, TripDeleteError},
|
||||
trip::{CoxHelpError, Trip, TripDeleteError, TripUpdateError},
|
||||
tripdetails::TripDetails,
|
||||
user::CoxUser,
|
||||
};
|
||||
@ -36,7 +36,31 @@ async fn create(db: &State<SqlitePool>, data: Form<AddTripForm>, cox: CoxUser) -
|
||||
//TODO: fix clone()
|
||||
Trip::new_own(db, cox.id, trip_details_id).await;
|
||||
|
||||
Flash::success(Redirect::to("/"), "Successfully planned the event")
|
||||
Flash::success(Redirect::to("/"), "Ausfahrt erfolgreich erstellt.")
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct EditTripForm {
|
||||
max_people: i32,
|
||||
notes: Option<String>,
|
||||
}
|
||||
|
||||
#[post("/trip/<trip_id>", data = "<data>")]
|
||||
async fn update(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<EditTripForm>,
|
||||
trip_id: i64,
|
||||
cox: CoxUser,
|
||||
) -> Flash<Redirect> {
|
||||
match Trip::update_own(db, cox.id, trip_id, data.max_people, data.notes.clone()).await {
|
||||
Ok(_) => Flash::success(Redirect::to("/"), "Ausfahrt erfolgreich aktualisiert."),
|
||||
Err(TripUpdateError::NotYourTrip) => {
|
||||
Flash::error(Redirect::to("/"), "Nicht deine Ausfahrt!")
|
||||
}
|
||||
Err(TripUpdateError::TripDoesNotExist) => {
|
||||
Flash::error(Redirect::to("/"), "Ausfahrt gibt's nicht")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/join/<planned_event_id>")]
|
||||
@ -75,5 +99,5 @@ async fn remove(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) ->
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![create, join, remove, remove_trip]
|
||||
routes![create, join, remove, remove_trip, update]
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
|
||||
.signed_duration_since(Local::now().date_naive())
|
||||
.num_days();
|
||||
}
|
||||
show_next_n_days = 2;
|
||||
|
||||
for i in 0..show_next_n_days + 1 {
|
||||
let date = (Local::now() + Duration::days(i)).date_naive();
|
||||
|
Reference in New Issue
Block a user