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 fa2a509..aaa52b8 100644 Binary files a/db.sqlite and b/db.sqlite differ 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 %}