use ::{models, utils}; use rocket_contrib::Json; #[derive(BartDisplay, Serialize)] #[template = "templates/index.html"] struct IndexTemplate { posts: Vec } implement_responder_for!(IndexTemplate); #[get("/", format = "text/html")] fn index(conn: utils::DbConn) -> utils::Page { utils::Page { title: String::from("Bloggen"), content: IndexTemplate { posts: models::Post::get_all(conn) } } } #[get("/", format = "application/json")] fn index_json(conn: utils::DbConn) -> Json> { Json(models::Post::get_all(conn)) }