diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-01-20 14:02:36 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-01-20 14:02:36 +0100 |
commit | 0096ed535d58552a3882e6b6672d5944abf40b81 (patch) | |
tree | 5fba6df63eee785ea8bd43a44751696cf62c52f4 /src/controllers | |
parent | 9849b618794d9114704fecf274b5de219bd686e8 (diff) | |
download | rocket-blog-0096ed535d58552a3882e6b6672d5944abf40b81.tar.gz rocket-blog-0096ed535d58552a3882e6b6672d5944abf40b81.tar.bz2 rocket-blog-0096ed535d58552a3882e6b6672d5944abf40b81.zip |
Refactor index template.
Use a vector of show post templates instead of manually decoding posts
in the index view.
Diffstat (limited to 'src/controllers')
-rw-r--r-- | src/controllers/home_controller.rs | 7 | ||||
-rw-r--r-- | src/controllers/posts_controller.rs | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs index d9a539a..2f657c3 100644 --- a/src/controllers/home_controller.rs +++ b/src/controllers/home_controller.rs @@ -2,11 +2,12 @@ use ::{models, utils}; use rocket; use rocket_contrib::Json; use std::path::PathBuf; +use posts_controller::ShowPostTemplate; #[derive(BartDisplay, Serialize)] #[template = "templates/index.html"] struct IndexTemplate { - posts: Vec<models::Post> + posts: Vec<ShowPostTemplate> } implement_responder_for!(IndexTemplate); @@ -17,7 +18,9 @@ fn index(flash: Option<rocket::request::FlashMessage>, conn: utils::DbConn) -> u title: String::from("Bloggen"), flash: flash.map_or(None, |f| Some(f.msg().to_string())), content: IndexTemplate { - posts: models::Post::get_all(conn) + posts: models::Post::get_all(conn).into_iter() + .map(|p| ShowPostTemplate { post: p }) + .collect() } } } diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index 5fdd60e..47f9ca1 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -27,10 +27,10 @@ fn create(post: Form<::models::NewPost>, conn: utils::DbConn) -> Flash<Redirect> Flash::success(Redirect::to("/"), "Post successfully created!") } -#[derive(BartDisplay)] +#[derive(BartDisplay, Serialize)] #[template = "templates/show_post.html"] pub struct ShowPostTemplate { - post: ::models::Post + pub post: ::models::Post } implement_responder_for!(ShowPostTemplate); |