From 7633b869d0ca0772f73c687023e299d7ce7e4b52 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 1 Aug 2018 13:50:01 +0200 Subject: Make imports explicit. --- src/controllers/home_controller.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/controllers/home_controller.rs') 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, conn: utils::DbConn) -> utils::Page { - utils::Page { +fn index(flash: Option, conn: DbConn) -> Page { + 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, conn: utils::DbConn) -> u } #[get("/", format = "application/json")] -fn index_json(conn: utils::DbConn) -> Json> { - Json(models::Post::get_all(conn)) +fn index_json(conn: DbConn) -> Json> { + Json(Post::get_all(conn)) } // // Serve files from the public directory if no routes matches. // #[get("/", rank = 99)] -fn public_file(file: PathBuf) -> Option { - rocket::response::NamedFile::open(PathBuf::from("public/").join(file)).ok() +fn public_file(file: PathBuf) -> Option { + NamedFile::open(PathBuf::from("public/").join(file)).ok() } -pub fn routes() -> Vec { +pub fn routes() -> Vec { routes![ index, index_json, -- cgit v1.2.3