don't panic :-)

This commit is contained in:
Philipp Hofer 2025-04-06 16:21:48 +02:00
parent a0e7fa4574
commit ea89962664
2 changed files with 25 additions and 6 deletions

BIN
db.sqlite

Binary file not shown.

View File

@ -21,15 +21,25 @@ async fn create(
session: Session, session: Session,
Form(form): Form<CreateForm>, Form(form): Form<CreateForm>,
) -> impl IntoResponse { ) -> impl IntoResponse {
Station::create(&db, &form.name).await.unwrap(); match Station::create(&db, &form.name).await{
Ok(_) =>
session session
.insert( .insert(
"succ", "succ",
&format!("Station '{}' erfolgreich erstellt!", form.name), &format!("Station '{}' erfolgreich erstellt!", form.name),
) )
.await .await
.unwrap(); .unwrap(),
Err(e) =>
session
.insert(
"err",
&format!("Station '{}' konnte _NICHT_ erstellt werden, da es bereits eine Station mit diesem Namen gibt ({e})!", form.name),
)
.await
.unwrap(),
}
Redirect::to("/station") Redirect::to("/station")
} }
@ -70,14 +80,23 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
let stations = Station::all(&db).await; let stations = Station::all(&db).await;
// Get and clear flash message // Get and clear flash message
let flash_message = session.get::<String>("succ").await.unwrap_or(None); let succ_msg = session.get::<String>("succ").await.unwrap_or(None);
if flash_message.is_some() { if succ_msg.is_some() {
session.remove::<String>("succ").await.unwrap(); session.remove::<String>("succ").await.unwrap();
} }
let err_msg = session.get::<String>("err").await.unwrap_or(None);
if err_msg.is_some() {
session.remove::<String>("err").await.unwrap();
}
html! { html! {
h1 { "Stationen" } h1 { "Stationen" }
@if let Some(message) = flash_message { @if let Some(message) = succ_msg {
div class="alert alert-success" {
(message)
}
}
@if let Some(message) = err_msg {
div class="alert alert-success" { div class="alert alert-success" {
(message) (message)
} }