diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index 0bbdc2e..be61d2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,37 +12,20 @@ extern crate r2d2_diesel; extern crate rocket; extern crate rocket_contrib; -use rocket_contrib::Json; - #[macro_use] mod utils; mod models; mod schema; mod controllers; +use controllers::home_controller; use controllers::posts_controller; -#[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)) -} - fn main() { rocket::ignite() .manage(utils::init_db_pool()) - .mount("/", routes![index, index_json]) + .mount("/", + routes![ + home_controller::index, + home_controller::index_json]) .mount("/posts", routes![ posts_controller::new, |