allow trip_type edit of trip

This commit is contained in:
2023-05-03 16:51:37 +02:00
parent 172901b80f
commit 787b28cc23
6 changed files with 20 additions and 7 deletions

View File

@ -11,6 +11,7 @@ use crate::model::{
planned_event::PlannedEvent,
trip::{CoxHelpError, Trip, TripDeleteError, TripUpdateError},
tripdetails::TripDetails,
triptype::TripType,
user::CoxUser,
};
@ -63,6 +64,7 @@ async fn create(db: &State<SqlitePool>, data: Form<AddTripForm>, cox: CoxUser) -
struct EditTripForm {
max_people: i32,
notes: Option<String>,
trip_type: Option<i64>,
}
#[post("/trip/<trip_id>", data = "<data>")]
@ -73,7 +75,16 @@ async fn update(
cox: CoxUser,
) -> Flash<Redirect> {
if let Some(trip) = Trip::find_by_id(db, trip_id).await {
match Trip::update_own(db, &cox, &trip, data.max_people, data.notes.clone()).await {
match Trip::update_own(
db,
&cox,
&trip,
data.max_people,
data.notes.clone(),
data.trip_type,
)
.await
{
Ok(_) => Flash::success(Redirect::to("/"), "Ausfahrt erfolgreich aktualisiert."),
Err(TripUpdateError::NotYourTrip) => {
Flash::error(Redirect::to("/"), "Nicht deine Ausfahrt!")