From 094b1e07225313c930c26dbeb73755f34a537ce4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 8 Apr 2018 20:01:32 +0200 Subject: feat(handlers): Add thread submission handler --- src/handlers.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/handlers.rs') diff --git a/src/handlers.rs b/src/handlers.rs index 446f59a4f3ac..cc4ac23c412d 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -74,3 +74,18 @@ pub fn forum_thread(state: State, thread_id: Path) -> 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, input: Form) -> 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() +} -- cgit 1.4.1