parent
7a8bcecc87
commit
5832b9f0b4
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -77,9 +77,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
@ -238,7 +238,7 @@ checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.19",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.38",
|
||||
"syn 1.0.39",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -510,9 +510,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
|
||||
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3"
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
@ -755,7 +755,7 @@ dependencies = [
|
||||
"pest_meta",
|
||||
"proc-macro2 1.0.19",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.38",
|
||||
"syn 1.0.39",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -787,9 +787,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
||||
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
@ -1055,7 +1055,7 @@ checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.19",
|
||||
"quote 1.0.7",
|
||||
"syn 1.0.38",
|
||||
"syn 1.0.39",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1136,9 +1136,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.38"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4"
|
||||
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.19",
|
||||
"quote 1.0.7",
|
||||
@ -1166,9 +1166,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed"
|
||||
checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
|
BIN
database.sqlite
BIN
database.sqlite
Binary file not shown.
69
src/main.rs
69
src/main.rs
@ -76,17 +76,24 @@ fn query_one_class<'a>(
|
||||
conn: DbConn,
|
||||
id: i32,
|
||||
) -> (Klasse, HashMap<String, (Stunde, Vec<Vertretung>)>) {
|
||||
//println!("Suche Vertretungen:");
|
||||
let mut ret: HashMap<String, (Stunde, Vec<Vertretung>)> = HashMap::new();
|
||||
let class = klassen::dsl::klassen
|
||||
.filter(klassen::dsl::klassen_id.eq(id))
|
||||
.first::<Klasse>(&*conn)
|
||||
.expect("database acess classes");
|
||||
//println!("Für die Klassen: {:?}", class);
|
||||
//let stund: Vec<Stunde> = stunden::table.load(&*conn).expect("Loading Stunden");
|
||||
let times: Vec<(Vertretung, Stunde)> = Vertretung::belonging_to(&class)
|
||||
.inner_join(stunden::table.on(vertretungen::stunde_id.eq(stunden::stunden_id)))
|
||||
.load(&*conn)
|
||||
.expect("database access Stunden");
|
||||
/*println!(
|
||||
"Gefunden: {:?}",
|
||||
diesel::debug_query::<diesel::sqlite::Sqlite, _>(×).to_string()
|
||||
);*/
|
||||
for (vert, stun) in times {
|
||||
//println!("{:?}, {:?}", vert, stun);
|
||||
let stun_ord = stun.ordinal.to_string();
|
||||
let verts = ret.entry(stun_ord).or_insert((stun, Vec::new()));
|
||||
verts.1.push(vert);
|
||||
@ -117,6 +124,7 @@ struct ListOneContext {
|
||||
fn klasse_view(conn: DbConn, class_id: i32) -> Template {
|
||||
let class = query_one_class(conn, class_id);
|
||||
let (klasse, vertretungen) = class;
|
||||
//println!("{:?}: {:?}", klasse, vertretungen);
|
||||
let cont = ListOneContext {
|
||||
klasse: klasse,
|
||||
vertretungen: vertretungen,
|
||||
@ -226,6 +234,64 @@ fn post_stunde_form(stunde: Form<StundeForm>, conn: DbConn) -> Result<Redirect,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct AddVertretungContext<'a> {
|
||||
vertretungen: Vec<Vertretung>,
|
||||
parent: &'a str,
|
||||
}
|
||||
|
||||
#[get("/add/vertretung")]
|
||||
fn get_vertretung_form(conn: DbConn) -> Template {
|
||||
let loc_vertretungen = vertretungen::table
|
||||
.order(vertretungen::klasse_id.asc())
|
||||
.load::<Vertretung>(&*conn)
|
||||
.expect("could not load vertretungen");
|
||||
Template::render(
|
||||
"add_vertretung_form",
|
||||
AddVertretungContext {
|
||||
vertretungen: loc_vertretungen,
|
||||
parent: "base",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/delete/vertretung/<vertretungen_id>")]
|
||||
fn delete_vertretung(vertretungen_id: i32, conn: DbConn) -> Result<Redirect, String> {
|
||||
match diesel::delete(
|
||||
schema::vertretungen::table
|
||||
.filter(schema::vertretungen::vertretungen_id.eq(vertretungen_id)),
|
||||
)
|
||||
.execute(&*conn)
|
||||
{
|
||||
Ok(_) => Ok(Redirect::to("/admin/add/vertretung")),
|
||||
Err(_) => Err("Vertretung konnte nicht gelöscht werden!".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm, Insertable)]
|
||||
#[table_name = "vertretungen"]
|
||||
struct VertretungForm {
|
||||
klasse_id: i32,
|
||||
stunde_id: i32,
|
||||
fehlend: String,
|
||||
vertretung: String,
|
||||
kommentar: String,
|
||||
}
|
||||
|
||||
#[post("/add/vertretung", data = "<vertretung>")]
|
||||
fn post_vertretung_form(
|
||||
vertretung: Form<VertretungForm>,
|
||||
conn: DbConn,
|
||||
) -> Result<Redirect, String> {
|
||||
match diesel::insert_into(schema::vertretungen::table)
|
||||
.values(vertretung.into_inner())
|
||||
.execute(&*conn)
|
||||
{
|
||||
Ok(_) => Ok(Redirect::to("/admin/add/vertretung")),
|
||||
Err(_) => Err("Vertretung konnte nicht erstellt werden!".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn mlen_helper_fun(
|
||||
h: &handlebars::Helper<'_, '_>,
|
||||
_: &handlebars::Handlebars,
|
||||
@ -267,7 +333,10 @@ fn main() {
|
||||
.mount("/admin/", routes![post_klasse_form])
|
||||
.mount("/admin/", routes![get_stunde_form])
|
||||
.mount("/admin/", routes![post_stunde_form])
|
||||
.mount("/admin/", routes![get_vertretung_form])
|
||||
.mount("/admin/", routes![post_vertretung_form])
|
||||
.mount("/admin/", routes![delete_stunde])
|
||||
.mount("/admin/", routes![delete_klasse])
|
||||
.mount("/admin/", routes![delete_vertretung])
|
||||
.launch();
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
{{#each vertretungen}}
|
||||
<tr>
|
||||
<th class="stunden">
|
||||
Stunde: {{this.0.title}}
|
||||
Stunde: {{this.0.short}}
|
||||
</th>
|
||||
{{#each this.1}}
|
||||
<td class="vertretung">
|
||||
|
Loading…
Reference in New Issue
Block a user