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·01+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T18·01+0200
commit094b1e07225313c930c26dbeb73755f34a537ce4 (patch)
tree10dd453d62684b13185e5f332cff5d34b336b0d7 /src/handlers.rs
parentfc7ca2900d656974891c7e5ccfd532ab93aade94 (diff)
feat(handlers): Add thread submission handler
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 446f59a4f3..cc4ac23c41 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -74,3 +74,18 @@ pub fn forum_thread(state: State<AppState>, thread_id: Path<i32>) -> ConverseRes
         })
         .responder()
 }
+
+/// This handler receives a "New thread"-form and redirects the user
+/// to the new thread after creation.
+pub fn submit_thread(state: State<AppState>, input: Form<NewThread>) -> ConverseResponse {
+    state.db.send(CreateThread(input.0))
+        .from_err()
+        .and_then(move |res| {
+            let thread = res?;
+            info!("Created new thread \"{}\" with ID {}", thread.title, thread.id);
+            Ok(HttpResponse::TemporaryRedirect()
+               .header("Location", format!("/thread/{}", thread.id))
+               .finish())
+        })
+        .responder()
+}