diff options
| author | Fuwn <[email protected]> | 2020-11-19 05:16:45 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-11-19 05:16:45 +0000 |
| commit | 4caa665aa3f323571c8f791588c7e1baeaaf6dc7 (patch) | |
| tree | 8fa9038d865b726d1d6b9508acd5cd3ef834b691 /src/api.rs | |
| parent | Create LICENSE.md (diff) | |
| download | chan-4caa665aa3f323571c8f791588c7e1baeaaf6dc7.tar.xz chan-4caa665aa3f323571c8f791588c7e1baeaaf6dc7.zip | |
repo: :star:
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") +} |