update logbook entries
This commit is contained in:
@ -20,11 +20,11 @@ use crate::model::{
|
||||
boatreservation::BoatReservation,
|
||||
log::Log,
|
||||
logbook::{
|
||||
LogToAdd, LogToFinalize, Logbook, LogbookCreateError, LogbookDeleteError,
|
||||
LogbookUpdateError,
|
||||
LogToAdd, LogToFinalize, LogToUpdate, Logbook, LogbookAdminUpdateError, LogbookCreateError,
|
||||
LogbookDeleteError, LogbookUpdateError,
|
||||
},
|
||||
logtype::LogType,
|
||||
user::{AdminUser, DonauLinzUser, User, UserWithDetails},
|
||||
user::{AdminUser, DonauLinzUser, User, UserWithDetails, VorstandUser},
|
||||
};
|
||||
|
||||
pub struct KioskCookie(());
|
||||
@ -282,10 +282,40 @@ async fn create_kiosk(
|
||||
create_logbook(db, data, &DonauLinzUser(creator)).await //TODO: fixme
|
||||
}
|
||||
|
||||
#[post("/update", data = "<data>")]
|
||||
async fn update(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<LogToUpdate>,
|
||||
user: VorstandUser,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(
|
||||
db,
|
||||
format!("User {} tries to update log entry={:?}", &user.name, data),
|
||||
)
|
||||
.await;
|
||||
|
||||
let data = data.into_inner();
|
||||
|
||||
let Some(logbook) = Logbook::find_by_id(db, data.id).await else {
|
||||
return Flash::error(Redirect::to("/log"), &format!("Logbucheintrag kann nicht bearbeitet werden, da es einen Logbuch-Eintrag mit ID={} nicht gibt", data.id));
|
||||
};
|
||||
|
||||
match logbook.update(db, data, &user.0).await {
|
||||
Ok(()) => Flash::success(
|
||||
Redirect::to("/log/show"),
|
||||
format!("Logbucheintrag erfolgreich bearbeitet"),
|
||||
),
|
||||
Err(LogbookAdminUpdateError::NotAllowed) => Flash::error(
|
||||
Redirect::to("/log/show"),
|
||||
format!("Du hast keine Erlaubnis, diesen Logbucheintrag zu bearbeiten!"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
async fn home_logbook(
|
||||
db: &SqlitePool,
|
||||
data: Form<LogToFinalize>,
|
||||
logbook_id: i32,
|
||||
logbook_id: i64,
|
||||
user: &DonauLinzUser,
|
||||
) -> Flash<Redirect> {
|
||||
let logbook: Option<Logbook> = Logbook::find_by_id(db, logbook_id).await;
|
||||
@ -312,7 +342,7 @@ async fn home_logbook(
|
||||
async fn home_kiosk(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<LogToFinalize>,
|
||||
logbook_id: i32,
|
||||
logbook_id: i64,
|
||||
_kiosk: KioskCookie,
|
||||
) -> Flash<Redirect> {
|
||||
let logbook = Logbook::find_by_id(db, logbook_id).await.unwrap(); //TODO: fixme
|
||||
@ -340,7 +370,7 @@ async fn home_kiosk(
|
||||
async fn home(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<LogToFinalize>,
|
||||
logbook_id: i32,
|
||||
logbook_id: i64,
|
||||
user: DonauLinzUser,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(
|
||||
@ -356,7 +386,7 @@ async fn home(
|
||||
}
|
||||
|
||||
#[get("/<logbook_id>/delete", rank = 2)]
|
||||
async fn delete(db: &State<SqlitePool>, logbook_id: i32, user: DonauLinzUser) -> Flash<Redirect> {
|
||||
async fn delete(db: &State<SqlitePool>, logbook_id: i64, user: DonauLinzUser) -> Flash<Redirect> {
|
||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||
if let Some(logbook) = logbook {
|
||||
Log::create(
|
||||
@ -385,7 +415,7 @@ async fn delete(db: &State<SqlitePool>, logbook_id: i32, user: DonauLinzUser) ->
|
||||
#[get("/<logbook_id>/delete")]
|
||||
async fn delete_kiosk(
|
||||
db: &State<SqlitePool>,
|
||||
logbook_id: i32,
|
||||
logbook_id: i64,
|
||||
_kiosk: KioskCookie,
|
||||
) -> Flash<Redirect> {
|
||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||
@ -425,7 +455,8 @@ pub fn routes() -> Vec<Route> {
|
||||
show_kiosk,
|
||||
show_for_year,
|
||||
delete,
|
||||
delete_kiosk
|
||||
delete_kiosk,
|
||||
update
|
||||
]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user