forked from Ruderverein-Donau-Linz/rowt
allow trip_type edit of trip
This commit is contained in:
parent
172901b80f
commit
787b28cc23
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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!")
|
||||
|
@ -5,9 +5,8 @@
|
||||
<input class="day-js" type="hidden" name="day" value="" />
|
||||
{{ 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') }}
|
||||
|
||||
<input value="Erstellen" class="w-full btn btn-primary" type="submit" />
|
||||
</form>
|
||||
|
@ -37,11 +37,11 @@
|
||||
</label>
|
||||
{% endmacro checkbox %}
|
||||
|
||||
{% macro select(trip_types, select_name='trip_type', default='') %}
|
||||
{% macro select(trip_types, select_name='trip_type', default='', selected_id='') %}
|
||||
<select name="{{ select_name }}" class="input rounded-md h-10">
|
||||
<option selected value>{{ default }}</option>
|
||||
{% for trip_type in trip_types %}
|
||||
<option value="{{ trip_type.id }}">{{ trip_type.name }}</option>
|
||||
<option value="{{ trip_type.id }}" {% if trip_type.id == selected_id %} selected {% endif %}>{{ trip_type.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endmacro select %}
|
||||
|
@ -205,6 +205,8 @@
|
||||
<form action="/cox/trip/{{ trip.id }}" method="post" class="grid gap-3">
|
||||
{{ 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) }}
|
||||
|
||||
<input value="Bearbeiten" class="btn btn-primary" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user