don't allow cox to help if cox is already registered as rower for event

This commit is contained in:
2023-04-05 21:49:48 +02:00
parent e2f5436790
commit 9ab1572b15
2 changed files with 47 additions and 17 deletions

View File

@ -6,7 +6,11 @@ use rocket::{
};
use sqlx::SqlitePool;
use crate::model::{trip::Trip, tripdetails::TripDetails, user::CoxUser};
use crate::model::{
trip::{CoxHelpError, Trip},
tripdetails::TripDetails,
user::CoxUser,
};
//TODO: add constraints (e.g. planned_amount_cox > 0)
#[derive(FromForm)]
@ -37,10 +41,15 @@ async fn create(db: &State<SqlitePool>, data: Form<AddTripForm>, cox: CoxUser) -
#[get("/join/<planned_event_id>")]
async fn join(db: &State<SqlitePool>, planned_event_id: i64, cox: CoxUser) -> Flash<Redirect> {
if Trip::new_join(db, cox.id, planned_event_id).await {
Flash::success(Redirect::to("/"), "Danke für's helfen!")
} else {
Flash::error(Redirect::to("/"), "Du nimmst bereits teil!")
match Trip::new_join(db, cox.id, planned_event_id).await {
Ok(_) => Flash::success(Redirect::to("/"), "Danke für's helfen!"),
Err(CoxHelpError::AlreadyRegisteredAsCox) => {
Flash::error(Redirect::to("/"), "Du hilfst bereits aus!")
}
Err(CoxHelpError::AlreadyRegisteredAsRower) => Flash::error(
Redirect::to("/"),
"Du hast dich bereits als Ruderer angemeldet!",
),
}
}