allow adding rowers to logbook
This commit is contained in:
@ -12,7 +12,7 @@ use tera::Context;
|
||||
|
||||
use crate::model::{
|
||||
boat::Boat,
|
||||
logbook::Logbook,
|
||||
logbook::{Logbook, LogbookCreateError},
|
||||
logtype::LogType,
|
||||
user::{AdminUser, User},
|
||||
};
|
||||
@ -24,7 +24,8 @@ async fn index(
|
||||
adminuser: AdminUser,
|
||||
) -> Template {
|
||||
let boats = Boat::all(db).await;
|
||||
let users = User::cox(db).await;
|
||||
let coxes = User::cox(db).await;
|
||||
let users = User::all(db).await;
|
||||
let logtypes = LogType::all(db).await;
|
||||
|
||||
let on_water = Logbook::on_water(db).await;
|
||||
@ -36,6 +37,7 @@ async fn index(
|
||||
}
|
||||
|
||||
context.insert("boats", &boats);
|
||||
context.insert("coxes", &coxes);
|
||||
context.insert("users", &users);
|
||||
context.insert("logtypes", &logtypes);
|
||||
context.insert("loggedin_user", &adminuser.user);
|
||||
@ -47,7 +49,7 @@ async fn index(
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct LogAddForm {
|
||||
boat_id: i64,
|
||||
boat_id: i32,
|
||||
shipmaster: i64,
|
||||
shipmaster_only_steering: bool,
|
||||
departure: String,
|
||||
@ -56,6 +58,7 @@ struct LogAddForm {
|
||||
distance_in_km: Option<i64>,
|
||||
comments: Option<String>,
|
||||
logtype: Option<i64>,
|
||||
rower: Vec<i64>,
|
||||
}
|
||||
|
||||
#[post("/", data = "<data>")]
|
||||
@ -77,14 +80,16 @@ async fn create(
|
||||
data.distance_in_km,
|
||||
data.comments.clone(), //TODO: fix
|
||||
data.logtype,
|
||||
data.rower.clone(), //TODO: fix
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt erfolgreich hinzugefügt"),
|
||||
Err(_) => Flash::error(Redirect::to("/log"), format!("Fehler beim hinzufügen!"))
|
||||
}
|
||||
|
||||
|
||||
Err(LogbookCreateError::BoatAlreadyOnWater) => Flash::error(Redirect::to("/log"), format!("Boot schon am Wasser")),
|
||||
Err(LogbookCreateError::BoatLocked) => Flash::error(Redirect::to("/log"), format!("Boot gesperrt")),
|
||||
Err(LogbookCreateError::BoatNotFound) => Flash::error(Redirect::to("/log"), format!("Boot gibt's ned")),
|
||||
Err(LogbookCreateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
@ -117,22 +122,18 @@ async fn home(
|
||||
data.destination.clone(), //TODO: fixme
|
||||
data.distance_in_km,
|
||||
data.comments.clone(), //TODO: fixme
|
||||
data.logtype
|
||||
data.logtype,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"),
|
||||
Err(_) =>
|
||||
Flash::error(
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"),
|
||||
Err(_) => Flash::error(
|
||||
Redirect::to("/log"),
|
||||
format!("Logbook with ID {} could not be updated!", logbook_id),
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![index, create, home]
|
||||
}
|
||||
|
Reference in New Issue
Block a user