aboutsummaryrefslogtreecommitdiff
path: root/src/api.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2020-11-19 05:16:45 +0000
committerFuwn <[email protected]>2020-11-19 05:16:45 +0000
commit4caa665aa3f323571c8f791588c7e1baeaaf6dc7 (patch)
tree8fa9038d865b726d1d6b9508acd5cd3ef834b691 /src/api.rs
parentCreate LICENSE.md (diff)
downloadchan-4caa665aa3f323571c8f791588c7e1baeaaf6dc7.tar.xz
chan-4caa665aa3f323571c8f791588c7e1baeaaf6dc7.zip
repo: :star:
Diffstat (limited to 'src/api.rs')
-rw-r--r--src/api.rs20
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")
+}