Simple rendering of stubbed article
This commit is contained in:
parent
139a5b51b6
commit
35e7bad7d2
5 changed files with 41 additions and 3 deletions
|
@ -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;
|
||||
|
|
12
src/models.rs
Normal file
12
src/models.rs
Normal file
|
@ -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,
|
||||
}
|
|
@ -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()
|
||||
},
|
||||
|
|
13
src/state.rs
13
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<Option<()>, Box<std::error::Error>> {
|
||||
Ok(None)
|
||||
pub fn find_article_by_slug(&self, slug: &str) -> Result<Option<models::Article>, Box<std::error::Error>> {
|
||||
Ok(Some(models::Article {
|
||||
id: 0,
|
||||
revision: 0,
|
||||
created: chrono::Local::now().naive_local(),
|
||||
title: slug.to_owned(),
|
||||
body: "Look at me!".to_owned(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
13
templates/article.html
Normal file
13
templates/article.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>{{id}}-{{revision}}</p>
|
||||
<p>{{created}}</p>
|
||||
|
||||
<h1>{{title}}</h1>
|
||||
<p>{{body}}</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue