aboutsummaryrefslogtreecommitdiffstats
path: root/src/posts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/posts.rs')
-rw-r--r--src/posts.rs27
1 files changed, 27 insertions, 0 deletions
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("/")
+}