diff options
Diffstat (limited to 'src/api.rs')
| -rw-r--r-- | src/api.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..8d8d2f2 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,20 @@ +use rocket::request::Form; +use rocket::response::Redirect; + +use crate::db::*; + +// POST: Create a new thread. +#[post("/post", data = "<thread>")] +pub fn post(thread: Form<Thread>) -> Redirect { + // Pretty rudimentary error handling. + match new_thread(Thread { + name: thread.name.clone(), + comment: thread.comment.clone(), + }) { + Ok(()) => { }, + Err(why) => println!("Error creating new thread: {}", why) + } + + // Redirect to all posts. + Redirect::to("/threads") +} |