parent
99b0c311c5
commit
7b0dd543b1
BIN
database.sqlite
BIN
database.sqlite
Binary file not shown.
26
src/main.rs
26
src/main.rs
@ -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(
|
fn mlen_helper_fun(
|
||||||
h: &handlebars::Helper<'_, '_>,
|
h: &handlebars::Helper<'_, '_>,
|
||||||
_: &handlebars::Handlebars,
|
_: &handlebars::Handlebars,
|
||||||
@ -194,5 +218,7 @@ fn main() {
|
|||||||
.mount("/", routes![klasse_view])
|
.mount("/", routes![klasse_view])
|
||||||
.mount("/admin/", routes![get_klasse_form])
|
.mount("/admin/", routes![get_klasse_form])
|
||||||
.mount("/admin/", routes![post_klasse_form])
|
.mount("/admin/", routes![post_klasse_form])
|
||||||
|
.mount("/admin/", routes![get_stunde_form])
|
||||||
|
.mount("/admin/", routes![post_stunde_form])
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::schema::{klassen, vertretungen};
|
use super::schema::{klassen, stunden, vertretungen};
|
||||||
use std::cmp::Eq;
|
use std::cmp::Eq;
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Serialize, Hash, PartialEq, Clone)]
|
#[derive(Queryable, Debug, Serialize, Hash, PartialEq, Clone)]
|
||||||
@ -43,3 +43,11 @@ pub struct NewKlasse {
|
|||||||
pub titel: Option<String>,
|
pub titel: Option<String>,
|
||||||
pub ordnung: i32,
|
pub ordnung: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Insertable)]
|
||||||
|
#[table_name = "stunden"]
|
||||||
|
pub struct NewStunde {
|
||||||
|
pub title: String,
|
||||||
|
pub short: String,
|
||||||
|
pub ordinal: i32,
|
||||||
|
}
|
||||||
|
25
templates/add_stunde_form.hbs
Normal file
25
templates/add_stunde_form.hbs
Normal 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)~}}
|
Loading…
Reference in New Issue
Block a user