aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2017-12-17 21:20:14 +0100
committerHarald Eilertsen <haraldei@anduin.net>2017-12-17 21:20:14 +0100
commitb5a32ebbc86d6b17f4cb00673eb38096fe82defb (patch)
tree08adcbd6900f222fc7272482c79aef3af784c293
parent4e960f65ac0a9fb10aa89664b067ba501b90100d (diff)
downloadrocket-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.rs32
-rw-r--r--src/posts.rs27
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("/")
+}