From 7b0dd543b1f49f045c5f0c125a55d48f61fb135a Mon Sep 17 00:00:00 2001 From: Dietrich Date: Fri, 7 Aug 2020 19:44:15 +0200 Subject: [PATCH] adding the possibility to add Stundes fixes: #1 --- database.sqlite | Bin 24576 -> 24576 bytes src/main.rs | 26 ++++++++++++++++++++++++++ src/models.rs | 10 +++++++++- templates/add_stunde_form.hbs | 25 +++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 templates/add_stunde_form.hbs diff --git a/database.sqlite b/database.sqlite index 104349862e143cea37625a61d45f7e4ff72dfd7a..42b76952ebd31b1cec0f816e2837c1dace4673de 100644 GIT binary patch delta 67 zcmZoTz}Rqrae_3X%0wAwMwN{TOZ2&z`S&vLzvsWszjw2s!Fqlv31(IXb#X>RJq5SK V, conn: DbConn) -> Result Template { + Template::render("add_stunde_form", AddKlasseContext { parent: "base" }) +} + +#[derive(FromForm, Insertable)] +#[table_name = "stunden"] +struct StundeForm { + title: String, + short: String, + ordinal: i32, +} + +#[post("/add/stunde", data = "")] +fn post_stunde_form(stunde: Form, conn: DbConn) -> Result { + match diesel::insert_into(schema::stunden::table) + .values(stunde.into_inner()) + .execute(&*conn) + { + Ok(_) => Ok(Redirect::to("/admin/add/stunde")), + Err(_) => Err("Klasse konnte nicht erstellt werden!".to_string()), + } +} + fn mlen_helper_fun( h: &handlebars::Helper<'_, '_>, _: &handlebars::Handlebars, @@ -194,5 +218,7 @@ fn main() { .mount("/", routes![klasse_view]) .mount("/admin/", routes![get_klasse_form]) .mount("/admin/", routes![post_klasse_form]) + .mount("/admin/", routes![get_stunde_form]) + .mount("/admin/", routes![post_stunde_form]) .launch(); } diff --git a/src/models.rs b/src/models.rs index 17dca6a..eec4b6e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,4 @@ -use super::schema::{klassen, vertretungen}; +use super::schema::{klassen, stunden, vertretungen}; use std::cmp::Eq; #[derive(Queryable, Debug, Serialize, Hash, PartialEq, Clone)] @@ -43,3 +43,11 @@ pub struct NewKlasse { pub titel: Option, pub ordnung: i32, } + +#[derive(Serialize, Insertable)] +#[table_name = "stunden"] +pub struct NewStunde { + pub title: String, + pub short: String, + pub ordinal: i32, +} diff --git a/templates/add_stunde_form.hbs b/templates/add_stunde_form.hbs new file mode 100644 index 0000000..fbf14f8 --- /dev/null +++ b/templates/add_stunde_form.hbs @@ -0,0 +1,25 @@ +{{#* inline "page"}} +

Stunde hinzu fügen

+
+ + + + + + + + + + + + + + + + + +
Titel:
Abkürzung:
Ordnung:
+
+{{/inline}} +{{! remove whitespaces with ~ }} +{{~> (parent)~}} \ No newline at end of file