aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers/home_controller.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers/home_controller.rs')
-rw-r--r--src/controllers/home_controller.rs28
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,