aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers/home_controller.rs
blob: c4c0c56ccaf5da07b3360b737905c5738f25a933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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))
}