aboutsummaryrefslogtreecommitdiff
path: root/src/api.rs
blob: 394745266e37bfc5a608d591da334c933ab6c37d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use rocket::request::Form;
use rocket::response::Redirect;

use crate::db::*;
use crate::structures::*;

/// POST: Create a new thread.
#[post("/post", data = "<thread>")]
pub fn post(thread: Form<Thread>) -> Redirect {
	// Pretty rudimentary error handling.
	match new_thread(Thread {
		board: thread.board.clone(),
		name: thread.name.clone(),
		comment: thread.comment.clone(),
	}) {
		Ok(()) => { },
		Err(why) => println!("Error creating new thread: {}", why)
	}

	// Redirect to all posts.
	Redirect::to(format!("/board/{}", thread.board))
}