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

@ -139,6 +139,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
trip: &Trip,
max_people: i32,
notes: Option<String>,
trip_type: Option<i64>, //TODO: Move to `TripType`
) -> Result<(), TripUpdateError> {
if !trip.is_trip_from_user(cox.id).await {
return Err(TripUpdateError::NotYourTrip);
@ -156,9 +157,10 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
};
sqlx::query!(
"UPDATE trip_details SET max_people = ?, notes = ? WHERE id = ?",
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ? WHERE id = ?",
max_people,
notes,
trip_type,
trip_details_id
)
.execute(db)

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!")