about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/handlers.rs17
-rw-r--r--src/main.rs3
2 files changed, 18 insertions, 2 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()
+}
diff --git a/src/main.rs b/src/main.rs
index ad1f81927d32..3269e2d4dc3c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -61,7 +61,8 @@ fn main() {
         App::with_state(AppState { db: db_addr.clone(), tera })
             .middleware(middleware::Logger::default())
             .resource("/", |r| r.method(Method::GET).with(forum_index))
-            .resource("/thread", |r| r.method(Method::POST).with2(submit_thread))
+            .resource("/thread/submit", |r| r.method(Method::POST).with2(submit_thread))
+            .resource("/thread/reply", |r| r.method(Method::POST).with2(reply_thread))
             .resource("/thread/{id}", |r| r.method(Method::GET).with2(forum_thread))})
         .bind(&bind_host).expect(&format!("Could not bind on '{}'", bind_host))
         .start();