diff options
Diffstat (limited to 'src/controllers/home_controller.rs')
-rw-r--r-- | src/controllers/home_controller.rs | 21 |
1 files changed, 21 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)) +} |