aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 9ed4ddc..86a6186 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,6 +26,10 @@ fn get_message(id: usize, db: &State<SharedDB>) -> Json<Response<Message, &'stat
}
#[get("/get_message_id_list/<id_start>/<id_end>")]
fn get_message_id_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json<Response<Vec<UID>, &'static str>> {
+ if id_end - id_start > 25 {
+ return Json(Response(Err("Request limit is 25")))
+ }
+
let lock = db.sdb.lock().unwrap();
let list = lock.get_message_id_list(id_start.into(), id_end.into());
@@ -35,6 +39,21 @@ fn get_message_id_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json
Json(Response(Ok(list)))
}
}
+#[get("/get_message_list/<id_start>/<id_end>")]
+fn get_message_list(id_start: u64, id_end: u64, db: &State<SharedDB>) -> Json<Response<Vec<Message>, &'static str>> {
+ if id_end - id_start > 25 {
+ return Json(Response(Err("Request limit is 25")))
+ }
+
+ let lock = db.sdb.lock().unwrap();
+ let list = lock.get_message_list(id_start.into(), id_end.into());
+
+ if list.len() == 0 {
+ Json(Response(Err("No messages")))
+ } else {
+ Json(Response(Ok(list)))
+ }
+}
#[get("/get_message_id_newest")]
fn get_message_id_newest(db: &State<SharedDB>) -> Json<Response<UID, &'static str>> {
let lock = db.sdb.lock().unwrap();
@@ -85,6 +104,13 @@ fn create_user(name: Json<String>, db: &State<SharedDB>) -> Json<Response<UID, &
Json(Response(lock.create_user(name.0)))
}
+#[delete("/delete_user", format = "application/json", data = "<id>")]
+fn delete_user(id: Json<UID>, db: &State<SharedDB>) -> Json<Response<&'static str, String>> {
+ let mut lock = db.sdb.lock().unwrap();
+
+ Json(Response(lock.delete_user(id.0)))
+}
+
#[get("/ping")]
fn ping() -> Json<Response<&'static str, &'static str>> {
Json(Response(Ok("pong")))
@@ -115,7 +141,9 @@ fn rocket() -> _ {
get_user_by_name,
get_message_id_newest,
delete_message,
+ delete_user,
+ get_message_list,
])
.mount("/", routes![api_index])
.manage(SharedDB{sdb: Mutex::new(database::Database::new())})
-}
+} \ No newline at end of file