diff --git a/src/main.rs b/src/main.rs index 059131e..272a002 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ +#[macro_use] extern crate bart_derive; #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_codegen; #[macro_use] extern crate lazy_static; +extern crate bart; +extern crate chrono; extern crate clap; extern crate futures; extern crate hyper; @@ -9,6 +12,7 @@ extern crate hyper; use std::net::SocketAddr; mod db; +mod models; mod schema; mod site; mod state; diff --git a/src/models.rs b/src/models.rs new file mode 100644 index 0000000..a504922 --- /dev/null +++ b/src/models.rs @@ -0,0 +1,12 @@ +use chrono; + +#[derive(BartDisplay, Debug, Queryable)] +#[template="templates/article.html"] +pub struct Article { + pub id: i32, + pub revision: i32, + pub created: chrono::NaiveDateTime, + + pub title: String, + pub body: String, +} diff --git a/src/site.rs b/src/site.rs index 97182ed..d832799 100644 --- a/src/site.rs +++ b/src/site.rs @@ -44,7 +44,7 @@ impl Service for Site { futures::finished( Response::new() .with_header(ContentType(TEXT_HTML.clone())) - .with_body(format!("Article found.")) + .with_body(format!("{}", article)) .with_status(hyper::StatusCode::Ok) ).boxed() }, diff --git a/src/state.rs b/src/state.rs index 1f87fd2..ccd0ca6 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,7 +1,10 @@ use std; +use chrono; use diesel::sqlite::SqliteConnection; +use models; + pub struct State { db_connection: SqliteConnection } @@ -11,7 +14,13 @@ impl State { State { db_connection } } - pub fn find_article_by_slug(&self, slug: &str) -> Result, Box> { - Ok(None) + pub fn find_article_by_slug(&self, slug: &str) -> Result, Box> { + Ok(Some(models::Article { + id: 0, + revision: 0, + created: chrono::Local::now().naive_local(), + title: slug.to_owned(), + body: "Look at me!".to_owned(), + })) } } diff --git a/templates/article.html b/templates/article.html new file mode 100644 index 0000000..c675879 --- /dev/null +++ b/templates/article.html @@ -0,0 +1,13 @@ + + + +{{title}} + + +

{{id}}-{{revision}}

+

{{created}}

+ +

{{title}}

+

{{body}}

+ +