don't panic :-)
This commit is contained in:
parent
a0e7fa4574
commit
ea89962664
@ -21,15 +21,25 @@ async fn create(
|
||||
session: Session,
|
||||
Form(form): Form<CreateForm>,
|
||||
) -> impl IntoResponse {
|
||||
Station::create(&db, &form.name).await.unwrap();
|
||||
|
||||
match Station::create(&db, &form.name).await{
|
||||
Ok(_) =>
|
||||
session
|
||||
.insert(
|
||||
"succ",
|
||||
&format!("Station '{}' erfolgreich erstellt!", form.name),
|
||||
)
|
||||
.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")
|
||||
}
|
||||
@ -70,14 +80,23 @@ async fn index(State(db): State<Arc<SqlitePool>>, session: Session) -> Markup {
|
||||
let stations = Station::all(&db).await;
|
||||
|
||||
// Get and clear flash message
|
||||
let flash_message = session.get::<String>("succ").await.unwrap_or(None);
|
||||
if flash_message.is_some() {
|
||||
let succ_msg = session.get::<String>("succ").await.unwrap_or(None);
|
||||
if succ_msg.is_some() {
|
||||
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! {
|
||||
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" {
|
||||
(message)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user