From 1934fef0ddf449d57fd1394f1b835f7a0a1468ff Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 8 Feb 2023 22:02:17 +0100 Subject: [PATCH] finish day CRU --- .gitignore | 1 + README.md | 1 + db.sqlite | Bin 24576 -> 24576 bytes src/main.rs | 20 +++++++++++++++----- templates/index.html.tera | 25 +++++++++++++------------ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 2f7896d..d34b3a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +db.sqlite diff --git a/README.md b/README.md index b963cf0..876aea5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ # Edge case - Trip in the morning on usi rowing day +- after N people (/ cox) -> red highlighted -> queue # Fancy - Every cox can define which boats they use diff --git a/db.sqlite b/db.sqlite index fa2a509aee5e9704c9f9543eab226e52d4791d11..aaa52b8c860c18371f36d5c9d755d0c19be9801c 100644 GIT binary patch delta 251 zcmZoTz}Rqrae_3X%0wAwMwN{T3-ty0dl^{y;~Dtl`S0-`=U>cUwpmcXm%m<=kyVjV zoYTm_$XM6FNY}uE$-u5RS#EQZ-X4!njUq=7{tW7Y@ delta 84 zcmZoTz}Rqrae_3X@I)DBM&XSK3-x&!7#NuOk2CPU=fB5)e6ygyPX5Wq?KR~28CexM lcsY#>jEr>+jC2hwxWEdpFz`R-|HOX0szp|7YYCX diff --git a/src/main.rs b/src/main.rs index 8cca19e..8b0b6e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; use chrono::Duration; use chrono::Local; +use rocket::response::Redirect; use rocket::{form::Form, fs::FileServer, State}; use rocket_dyn_templates::context; use rocket_dyn_templates::Template; @@ -49,17 +50,26 @@ struct DayForm { } #[put("/day", data = "")] -async fn create(db: &State, day: Form) -> Template { - let day = day::ActiveModel { - day: Set(chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap()), +async fn create(db: &State, day: Form) -> Redirect { + let id = chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap(); + let new_day = day::ActiveModel { + day: Set(id), planned_amount_cox: Set(day.planned_amount_cox), planned_starting_time: Set(day.planned_starting_time.clone()), open_registration: Set(day.open_registration), }; - day.insert(db.inner()).await.unwrap(); //TODO: fixme + let day: Option = day::Entity::find_by_id(id).one(db.inner()).await.unwrap(); + match day { + Some(_) => { + new_day.update(db.inner()).await.unwrap(); //TODO: fixme + } + None => { + new_day.insert(db.inner()).await.unwrap(); //TODO: fixme + } + } - Template::render("index", context! {}) + Redirect::to("/") } #[launch] diff --git a/templates/index.html.tera b/templates/index.html.tera index d90119f..d6eaa7e 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -7,43 +7,44 @@
{% if days[day_string] and days[day_string].planned_amount_cox > 0%} - {% set day = days[day_string] %} - Geplante Steuerpersonen: {{ day.planned_amount_cox}}
- Geplante Abfahrtszeit: {{ day.planned_starting_time }}
- {% if day.open_registration %} + {% set cur_day = days[day_string] %} + Geplante Steuerpersonen: {{ cur_day.planned_amount_cox}}
+ Geplante Abfahrtszeit: {{ cur_day.planned_starting_time }}
+ {% if cur_day.open_registration %} ANMELDEN {% else %} Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen) {% endif %} {% else %} (Noch) keine Ausfahrt geplant + {% endif %} +
- + +
- +
- +
- +
- +
- +
- {% endif %} - +
{% endfor %}