adding the possibility to add Stundes

fixes: #1
This commit is contained in:
Dietrich 2020-08-07 19:44:15 +02:00
parent 99b0c311c5
commit 7b0dd543b1
4 changed files with 60 additions and 1 deletions

Binary file not shown.

View File

@ -155,6 +155,30 @@ fn post_klasse_form(klasse: Form<KlasseForm>, conn: DbConn) -> Result<Redirect,
}
}
#[get("/add/stunde")]
fn get_stunde_form() -> 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 = "<stunde>")]
fn post_stunde_form(stunde: Form<StundeForm>, conn: DbConn) -> Result<Redirect, String> {
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();
}

View File

@ -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<String>,
pub ordnung: i32,
}
#[derive(Serialize, Insertable)]
#[table_name = "stunden"]
pub struct NewStunde {
pub title: String,
pub short: String,
pub ordinal: i32,
}

View File

@ -0,0 +1,25 @@
{{#* inline "page"}}
<h1>Stunde hinzu fügen</h1>
<form action="/admin/add/stunde" method="post" accept-charset="utf-8">
<table>
<tr>
<th>Titel:</th>
<td><input type="text" name="title"></td>
</tr>
<tr>
<th>Abkürzung:</th>
<td><input type="text" name="short"></td>
</tr>
<tr>
<th>Ordnung:</th>
<td><input type="number" name="ordinal"></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Stunde Erstellen"></td>
</tr>
</table>
</form>
{{/inline}}
{{! remove whitespaces with ~ }}
{{~> (parent)~}}