aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 55131fcdc5a2130b0a3971be1621f9903cfc5e5d (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
26
27
28
29
30
31
32
33
34
35
#![feature(plugin)]
#![plugin(rocket_codegen)]

extern crate diesel;
extern crate rocket;
extern crate rocket_blog;
#[macro_use] extern crate bart_derive;

use self::diesel::prelude::*;
use self::rocket_blog::{schema, models};

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

#[get("/")]
fn index(conn: rocket_blog::DbConn) -> String {
    use schema::posts::dsl::*;
    let results = posts.filter(published.eq(false))
        .limit(5)
        .load::<models::Post>(&*conn)
        .expect("Error loading posts");

    format!("{}", &IndexTemplate{ title: "Bloggen", posts: results })
}

fn main() {
    rocket::ignite()
        .manage(rocket_blog::init_db_pool())
        .mount("/", routes![index])
        .launch();
}