From 787b28cc23fb462ecb2ae6c0ae3558ae17280cf2 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 3 May 2023 16:51:37 +0200 Subject: [PATCH] allow trip_type edit of trip --- README.md | 1 - src/model/trip.rs | 4 +++- src/rest/cox.rs | 13 ++++++++++++- templates/forms/trip.html.tera | 3 +-- templates/includes/macros.html.tera | 4 ++-- templates/index.html.tera | 2 ++ 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index af88553..d40bc4c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ - [] FAQ page ## Backend -- [] allow edit of `trip_types` - [] Allow sign-outs only >2h before event - [] add `always_show` to `planned_trips` (e.g. for wanderfahrten) - [] `planned_events` -> ICS feed to be [integrated](https://icscalendar.com/shortcode-overview/) in homepage calendar diff --git a/src/model/trip.rs b/src/model/trip.rs index 6314e7a..5ca9b72 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -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, + trip_type: Option, //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) diff --git a/src/rest/cox.rs b/src/rest/cox.rs index b2715da..bbe77f7 100644 --- a/src/rest/cox.rs +++ b/src/rest/cox.rs @@ -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, data: Form, cox: CoxUser) - struct EditTripForm { max_people: i32, notes: Option, + trip_type: Option, } #[post("/trip/", data = "")] @@ -73,7 +75,16 @@ async fn update( cox: CoxUser, ) -> Flash { 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!") diff --git a/templates/forms/trip.html.tera b/templates/forms/trip.html.tera index af4d91b..d669f23 100644 --- a/templates/forms/trip.html.tera +++ b/templates/forms/trip.html.tera @@ -5,9 +5,8 @@ {{ macros::input(label='Startzeit (zB "10:00")', name='planned_starting_time', type='time', required=true) }} {{ macros::input(label='Anzahl Ruderer (ohne Steuerperson)', name='max_people', type='number', required=true, min='0') }} - {{ macros::checkbox(label='Gäste erlauben', name='allow_guests') }} + {{ macros::checkbox(label='Gäste erlauben', name='allow_guests') }} {{ macros::input(label='Anmerkungen', name='notes', type='input') }} - {{ macros::select(select_name='trip_type', trip_types=trip_types, default='Reguläre Ausfahrt') }} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 1f1216f..09c10dd 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -37,11 +37,11 @@ {% endmacro checkbox %} -{% macro select(trip_types, select_name='trip_type', default='') %} +{% macro select(trip_types, select_name='trip_type', default='', selected_id='') %} {% endmacro select %} diff --git a/templates/index.html.tera b/templates/index.html.tera index ca20de4..5eea2ce 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -205,6 +205,8 @@
{{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true, value=trip.max_people, min='0') }} {{ macros::input(label='Anmerkungen', name='notes', type='input', value=trip.notes) }} + {{ macros::select(select_name='trip_type', trip_types=trip_types, default='Reguläre Ausfahrt', selected_id=trip.trip_type_id) }} +