aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers/home_controller.rs
blob: 563be40abced1de24ced4eedcba6f0716ddbd3bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use ::{models, utils};
use rocket_contrib::Json;

#[derive(BartDisplay, Serialize)]
#[template = "templates/index.html"]
struct IndexTemplate {
    posts: Vec<models::Post>
}

implement_responder_for!(IndexTemplate);

#[get("/", format = "text/html")]
fn index(conn: utils::DbConn) -> utils::Page<IndexTemplate> {
    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<Vec<models::Post>> {
    Json(models::Post::get_all(conn))
}