about summary refs log tree commit diff
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T18·20+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T18·20+0200
commitcf636077e65ae4c8598fd32aa9b233b87070875e (patch)
tree3f149480deed7d04af0cf5f5f70090d5495a056e /src/handlers.rs
parent148dfc39c80266e9c3077737e4258739dba7d86a (diff)
feat(handlers): Add reply_thread handler for posts
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index cc4ac23c412d..a16f73389fad 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -83,9 +83,24 @@ pub fn submit_thread(state: State<AppState>, input: Form<NewThread>) -> Converse
         .and_then(move |res| {
             let thread = res?;
             info!("Created new thread \"{}\" with ID {}", thread.title, thread.id);
-            Ok(HttpResponse::TemporaryRedirect()
+            Ok(HttpResponse::SeeOther()
                .header("Location", format!("/thread/{}", thread.id))
                .finish())
         })
         .responder()
 }
+
+/// This handler receives a "Reply"-form and redirects the user to the
+/// new post after creation.
+pub fn reply_thread(state: State<AppState>, input: Form<NewPost>) -> ConverseResponse {
+    state.db.send(CreatePost(input.0))
+        .from_err()
+        .and_then(move |res| {
+            let post = res?;
+            info!("Posted reply {} to thread {}", post.id, post.thread_id);
+            Ok(HttpResponse::SeeOther()
+               .header("Location", format!("/thread/{}#post{}", post.thread_id, post.id))
+               .finish())
+        })
+        .responder()
+}