diff options
author | curly <curlybryce@protonmail.com> | 2023-02-09 09:27:58 -0700 |
---|---|---|
committer | curly <curlybryce@protonmail.com> | 2023-02-09 09:27:58 -0700 |
commit | 7bbc871e3402fdedec8f07c8969a8877b87fae18 (patch) | |
tree | b92cd1eca5b55f927aff7b76b8d655ce3298b4c2 /src/main.rs | |
parent | 58300710ed6bc9f0734fa3fbdaac6c38dfb8a790 (diff) | |
download | rocket_test-7bbc871e3402fdedec8f07c8969a8877b87fae18.tar.gz rocket_test-7bbc871e3402fdedec8f07c8969a8877b87fae18.tar.bz2 rocket_test-7bbc871e3402fdedec8f07c8969a8877b87fae18.zip |
message_list, delete_user, limits
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 30 |
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 |