finish tests
This commit is contained in:
@ -12,6 +12,7 @@ use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
log::Log,
|
||||
tripdetails::TripDetails,
|
||||
user::User,
|
||||
usertrip::{UserTrip, UserTripError},
|
||||
Day,
|
||||
@ -51,7 +52,11 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
|
||||
|
||||
#[get("/join/<trip_details_id>")]
|
||||
async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
||||
match UserTrip::create(db, user.id, trip_details_id).await {
|
||||
let trip_details = match TripDetails::find_by_id(db, trip_details_id).await {
|
||||
Some(trip_details) => trip_details,
|
||||
None => return Flash::error(Redirect::to("/"), "Trip_details do not exist."),
|
||||
};
|
||||
match UserTrip::create(db, &user, &trip_details).await {
|
||||
Ok(_) => {
|
||||
Log::create(
|
||||
db,
|
||||
@ -72,15 +77,23 @@ async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash
|
||||
Err(UserTripError::AlreadyRegisteredAsCox) => {
|
||||
Flash::error(Redirect::to("/"), "Du hilfst bereits als Steuerperson aus!")
|
||||
}
|
||||
Err(UserTripError::TripDetailsNotFound) => {
|
||||
Flash::error(Redirect::to("/"), "Trip_details do not exist.")
|
||||
}
|
||||
Err(UserTripError::CantRegisterAtOwnEvent) => Flash::error(
|
||||
Redirect::to("/"),
|
||||
"Du kannst bei einer selbst ausgeschriebenen Fahrt nicht mitrudern ;)",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/remove/<trip_details_id>")]
|
||||
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
||||
UserTrip::delete(db, user.id, trip_details_id).await;
|
||||
let trip_details = match TripDetails::find_by_id(db, trip_details_id).await {
|
||||
Some(trip_details) => trip_details,
|
||||
None => {
|
||||
return Flash::error(Redirect::to("/"), "TripDetailsId does not exist");
|
||||
}
|
||||
};
|
||||
|
||||
UserTrip::delete(db, &user, &trip_details).await;
|
||||
|
||||
Log::create(
|
||||
db,
|
||||
|
Reference in New Issue
Block a user