diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-08-22 17:02:30 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-08-22 17:02:30 +0200 |
commit | 3267754478ea1b83c3da653c4a5f9706c9fdce05 (patch) | |
tree | 30ad507bddf03dce50d833040948c904b2dffa2c /src | |
parent | 2b8fdbe9200d6950bfd10f42e5af0e424effafd8 (diff) | |
download | ramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.tar.gz ramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.tar.bz2 ramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.zip |
Use Tera templates to render pages.
Diffstat (limited to 'src')
-rw-r--r-- | src/controllers/room.rs | 17 | ||||
-rw-r--r-- | src/lib.rs | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/controllers/room.rs b/src/controllers/room.rs index 419afae..43d3e60 100644 --- a/src/controllers/room.rs +++ b/src/controllers/room.rs @@ -24,9 +24,22 @@ use crate::{ use rocket::get; use rocket_contrib::{ json::Json, + templates::Template, }; +use serde::Serialize; -#[get("/")] -pub fn get_rooms(db: db::Connection) -> Json<Vec<models::Room>> { +#[derive(Serialize)] +struct Context { + rooms : Vec<models::Room>, +} + +#[get("/", rank = 1)] +pub fn list_rooms(db: db::Connection) -> Template { + let ctx = Context { rooms: db.get_rooms().unwrap() }; + Template::render("room/list", &ctx) +} + +#[get("/", format = "application/json", rank = 2)] +pub fn get_rooms_json(db: db::Connection) -> Json<Vec<models::Room>> { Json(db.get_rooms().unwrap()) } @@ -42,8 +42,9 @@ pub fn build_rocket(db_url: &str) -> Result<rocket::Rocket, Box<dyn Error>> { Ok(rocket::custom(config) .attach(db::Connection::fairing()) + .attach(rocket_contrib::templates::Template::fairing()) .mount("/", rocket_contrib::serve::StaticFiles::from("./public")) - .mount("/rooms", routes![room::get_rooms]) + .mount("/rooms", routes![room::get_rooms_json, room::list_rooms]) .mount("/films", routes![film::get_films]) .mount("/screenings", routes![screening::get_aggregated_screenings])) } |