don't allow cox to help if cox is already registered as rower for event
This commit is contained in:
@ -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!",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user