diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2017-12-17 21:20:14 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2017-12-17 21:20:14 +0100 |
commit | b5a32ebbc86d6b17f4cb00673eb38096fe82defb (patch) | |
tree | 08adcbd6900f222fc7272482c79aef3af784c293 | |
parent | 4e960f65ac0a9fb10aa89664b067ba501b90100d (diff) | |
download | rocket-blog-b5a32ebbc86d6b17f4cb00673eb38096fe82defb.tar.gz rocket-blog-b5a32ebbc86d6b17f4cb00673eb38096fe82defb.tar.bz2 rocket-blog-b5a32ebbc86d6b17f4cb00673eb38096fe82defb.zip |
Move posts module to it's own source file.
-rw-r--r-- | src/main.rs | 32 | ||||
-rw-r--r-- | src/posts.rs | 27 |
2 files changed, 29 insertions, 30 deletions
diff --git a/src/main.rs b/src/main.rs index c94dab5..f89a39f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,8 @@ use rocket::request::Request; use rocket::http::{ContentType, Status}; use std::io::Cursor; +mod posts; + #[derive(BartDisplay, Serialize)] #[template = "templates/index.html"] struct IndexTemplate<'a> { @@ -63,36 +65,6 @@ fn index_json(conn: rocket_blog::DbConn) -> Json<Vec<models::Post>> { Json(get_posts(conn)) } -mod posts { - use rocket::request::Form; - use rocket::response::Redirect; - use diesel::{self, ExecuteDsl}; - - #[derive(BartDisplay)] - #[template = "templates/new_post.html"] - pub struct NewPostTemplate<'a> { - title: &'a str, - post: ::models::NewPost - } - - #[get("/new", format = "text/html")] - fn new<'a>(_conn: ::rocket_blog::DbConn) -> NewPostTemplate<'a> { - NewPostTemplate { title: "Bloggen", post: Default::default() } - } - - #[post("/create", data="<post>")] - fn create(post: Form<::models::NewPost>, conn: ::rocket_blog::DbConn) -> Redirect { - use ::schema::posts; - - diesel::insert(post.get()) - .into(posts::table) - .execute(&*conn) - .expect("Error saving post."); - - Redirect::to("/") - } -} - fn main() { rocket::ignite() .manage(rocket_blog::init_db_pool()) diff --git a/src/posts.rs b/src/posts.rs new file mode 100644 index 0000000..a98ea5c --- /dev/null +++ b/src/posts.rs @@ -0,0 +1,27 @@ +use rocket::request::Form; +use rocket::response::Redirect; +use diesel::{self, ExecuteDsl}; + +#[derive(BartDisplay)] +#[template = "templates/new_post.html"] +pub struct NewPostTemplate<'a> { + title: &'a str, + post: ::models::NewPost +} + +#[get("/new", format = "text/html")] +fn new<'a>(_conn: ::rocket_blog::DbConn) -> NewPostTemplate<'a> { + NewPostTemplate { title: "Bloggen", post: Default::default() } +} + +#[post("/create", data="<post>")] +fn create(post: Form<::models::NewPost>, conn: ::rocket_blog::DbConn) -> Redirect { + use ::schema::posts; + + diesel::insert(post.get()) + .into(posts::table) + .execute(&*conn) + .expect("Error saving post."); + + Redirect::to("/") +} |