add functionality to finish logbook trips
This commit is contained in:
@ -64,7 +64,7 @@ async fn create(
|
||||
data: Form<LogAddForm>,
|
||||
_adminuser: AdminUser,
|
||||
) -> Flash<Redirect> {
|
||||
if Logbook::create(
|
||||
match Logbook::create(
|
||||
db,
|
||||
data.boat_id,
|
||||
data.shipmaster,
|
||||
@ -80,14 +80,61 @@ async fn create(
|
||||
)
|
||||
.await
|
||||
{
|
||||
Flash::success(Redirect::to("/log"), "Ausfahrt erfolgreich hinzugefügt")
|
||||
} else {
|
||||
Flash::error(Redirect::to("/log"), format!("Fehler beim hinzufügen!"))
|
||||
}
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt erfolgreich hinzugefügt"),
|
||||
Err(_) => Flash::error(Redirect::to("/log"), format!("Fehler beim hinzufügen!"))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct LogHomeForm {
|
||||
destination: String,
|
||||
distance_in_km: i64,
|
||||
comments: Option<String>,
|
||||
logtype: Option<i64>,
|
||||
}
|
||||
|
||||
#[post("/<logbook_id>", data = "<data>")]
|
||||
async fn home(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<LogHomeForm>,
|
||||
logbook_id: i32,
|
||||
_adminuser: AdminUser,
|
||||
) -> Flash<Redirect> {
|
||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||
let Some(logbook) = logbook else {
|
||||
return Flash::error(
|
||||
Redirect::to("/admin/log"),
|
||||
format!("Log with ID {} does not exist!", logbook_id),
|
||||
)
|
||||
};
|
||||
|
||||
match logbook
|
||||
.home(
|
||||
db,
|
||||
&_adminuser.user,
|
||||
data.destination.clone(), //TODO: fixme
|
||||
data.distance_in_km,
|
||||
data.comments.clone(), //TODO: fixme
|
||||
data.logtype
|
||||
)
|
||||
.await
|
||||
{
|
||||
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]
|
||||
routes![index, create, home]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user