aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-01-11 22:57:24 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-01-11 22:57:24 +0100
commit0a7015b2b1d1e6682385ff3c02f14c1911158a8e (patch)
tree1edcbb594a1b4b0d9133ed7c38452655a8842cf0 /src/controllers
parentbf2578d19a04adeb2438ba81280327e885c1ded9 (diff)
downloadrocket-blog-0a7015b2b1d1e6682385ff3c02f14c1911158a8e.tar.gz
rocket-blog-0a7015b2b1d1e6682385ff3c02f14c1911158a8e.tar.bz2
rocket-blog-0a7015b2b1d1e6682385ff3c02f14c1911158a8e.zip
Move homepage processing to separate controller.
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/home_controller.rs21
-rw-r--r--src/controllers/mod.rs1
2 files changed, 22 insertions, 0 deletions
diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs
new file mode 100644
index 0000000..c4c0c56
--- /dev/null
+++ b/src/controllers/home_controller.rs
@@ -0,0 +1,21 @@
+use ::{models, utils};
+use rocket_contrib::Json;
+
+#[derive(BartDisplay, Serialize)]
+#[template = "templates/index.html"]
+struct IndexTemplate<'a> {
+ title: &'a str,
+ posts: Vec<models::Post>
+}
+
+implement_responder_for!(IndexTemplate<'a>);
+
+#[get("/", format = "text/html")]
+fn index<'a>(conn: utils::DbConn) -> IndexTemplate<'a> {
+ IndexTemplate { title: "Bloggen", posts: models::Post::get_all(conn) }
+}
+
+#[get("/", format = "application/json")]
+fn index_json(conn: utils::DbConn) -> Json<Vec<models::Post>> {
+ Json(models::Post::get_all(conn))
+}
diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs
index 0a95bd5..b23cd61 100644
--- a/src/controllers/mod.rs
+++ b/src/controllers/mod.rs
@@ -1 +1,2 @@
+pub mod home_controller;
pub mod posts_controller;