aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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("/")
+}