implement is_locked for trip_details

This commit is contained in:
2023-08-09 11:54:18 +02:00
parent 21c5609b31
commit bd4ee5954c
9 changed files with 150 additions and 47 deletions

View File

@ -9,7 +9,7 @@ use sqlx::SqlitePool;
use crate::model::{
log::Log,
planned_event::PlannedEvent,
trip::{CoxHelpError, Trip, TripDeleteError, TripUpdateError},
trip::{CoxHelpError, Trip, TripDeleteError, TripHelpDeleteError, TripUpdateError},
tripdetails::{TripDetails, TripDetailsToAdd},
user::CoxUser,
};
@ -43,6 +43,7 @@ struct EditTripForm<'r> {
notes: Option<&'r str>,
trip_type: Option<i64>,
always_show: bool,
is_locked: bool,
}
#[post("/trip/<trip_id>", data = "<data>")]
@ -61,6 +62,7 @@ async fn update(
data.notes,
data.trip_type,
data.always_show,
data.is_locked,
)
.await
{
@ -99,6 +101,9 @@ async fn join(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) -> Fl
Redirect::to("/"),
"Du hast dich bereits als Ruderer angemeldet!",
),
Err(CoxHelpError::DetailsLocked) => {
Flash::error(Redirect::to("/"), "Boot ist bereits eingeteilt.")
}
}
} else {
Flash::error(Redirect::to("/"), "Event gibt's nicht")
@ -129,19 +134,25 @@ async fn remove_trip(db: &State<SqlitePool>, trip_id: i64, cox: CoxUser) -> Flas
#[get("/remove/<planned_event_id>")]
async fn remove(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) -> Flash<Redirect> {
if let Some(planned_event) = PlannedEvent::find_by_id(db, planned_event_id).await {
if Trip::delete_by_planned_event(db, &cox, &planned_event).await {
Log::create(
db,
format!(
"Cox {} deleted registration for planned_event.id={}",
cox.name, planned_event_id
),
)
.await;
match Trip::delete_by_planned_event(db, &cox, &planned_event).await {
Ok(_) => {
Log::create(
db,
format!(
"Cox {} deleted registration for planned_event.id={}",
cox.name, planned_event_id
),
)
.await;
Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!")
} else {
Flash::error(Redirect::to("/"), "Steuermann hilft nicht aus...")
return Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!");
}
Err(TripHelpDeleteError::DetailsLocked) => {
return Flash::error(Redirect::to("/"), "Boot bereits eingeteilt");
}
Err(TripHelpDeleteError::CoxNotHelping) => {
return Flash::error(Redirect::to("/"), "Steuermann hilft nicht aus...")
}
}
} else {
Flash::error(Redirect::to("/"), "Planned_event does not exist.")