diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 13:50:01 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 19:40:40 +0200 |
commit | 7633b869d0ca0772f73c687023e299d7ce7e4b52 (patch) | |
tree | a6680ecd5951421861f8d03ca7404867fcb5efbf /src/controllers/home_controller.rs | |
parent | e569a688d9678e14f048003b15d076d1d57a3b55 (diff) | |
download | rocket-blog-7633b869d0ca0772f73c687023e299d7ce7e4b52.tar.gz rocket-blog-7633b869d0ca0772f73c687023e299d7ce7e4b52.tar.bz2 rocket-blog-7633b869d0ca0772f73c687023e299d7ce7e4b52.zip |
Make imports explicit.
Diffstat (limited to 'src/controllers/home_controller.rs')
-rw-r--r-- | src/controllers/home_controller.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs index 38db52a..6cfa736 100644 --- a/src/controllers/home_controller.rs +++ b/src/controllers/home_controller.rs @@ -1,5 +1,13 @@ -use ::{models, utils}; -use rocket; +use models::Post; +use utils::{ + DbConn, + Page +}; +use rocket::{ + response::NamedFile, + request::FlashMessage, + Route +}; use rocket_contrib::Json; use std::path::PathBuf; use posts_controller::ShowPostTemplate; @@ -13,12 +21,12 @@ struct IndexTemplate { implement_responder_for!(IndexTemplate); #[get("/", format = "text/html")] -fn index(flash: Option<rocket::request::FlashMessage>, conn: utils::DbConn) -> utils::Page<IndexTemplate> { - utils::Page { +fn index(flash: Option<FlashMessage>, conn: DbConn) -> Page<IndexTemplate> { + Page { title: String::from("Bloggen"), flash: flash, content: IndexTemplate { - posts: models::Post::get_all(conn).into_iter() + posts: Post::get_all(conn).into_iter() .map(|p| ShowPostTemplate { post: p }) .collect() } @@ -26,19 +34,19 @@ fn index(flash: Option<rocket::request::FlashMessage>, conn: utils::DbConn) -> u } #[get("/", format = "application/json")] -fn index_json(conn: utils::DbConn) -> Json<Vec<models::Post>> { - Json(models::Post::get_all(conn)) +fn index_json(conn: DbConn) -> Json<Vec<Post>> { + Json(Post::get_all(conn)) } // // Serve files from the public directory if no routes matches. // #[get("/<file..>", rank = 99)] -fn public_file(file: PathBuf) -> Option<rocket::response::NamedFile> { - rocket::response::NamedFile::open(PathBuf::from("public/").join(file)).ok() +fn public_file(file: PathBuf) -> Option<NamedFile> { + NamedFile::open(PathBuf::from("public/").join(file)).ok() } -pub fn routes() -> Vec<rocket::Route> { +pub fn routes() -> Vec<Route> { routes![ index, index_json, |