Now responding with http status codes. 404 when no queue is found, 202 when queue is empty.
parent
7afdaf8c82
commit
0fc4f16e62
18
src/main.rs
18
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use rocket::State;
|
||||
use rocket::{State, http::Status};
|
||||
use std::{sync::RwLock, collections::{VecDeque, HashMap}};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -27,19 +27,23 @@ fn index() -> &'static str {
|
|||
|
||||
|
||||
#[get("/<id>")]
|
||||
fn get_by_id(id: &str, dumb_queue: &State<DumbQueue>) -> String {
|
||||
fn get_by_id(id: &str, dumb_queue: &State<DumbQueue>) -> Result<String, Status> {
|
||||
|
||||
let queue_map = &dumb_queue.queue_map;
|
||||
let queues = &dumb_queue.queues;
|
||||
match queue_map.read().unwrap().get(id) {
|
||||
let map_reader = queue_map.read().unwrap();
|
||||
match map_reader.get(id) {
|
||||
Some(i) => {
|
||||
match queues.read().unwrap()[*i]
|
||||
let index = *i;
|
||||
drop(map_reader);
|
||||
|
||||
match queues.read().unwrap()[index]
|
||||
.write().unwrap().pop_front() {
|
||||
Some(res) => return res,
|
||||
None => String::from("")
|
||||
Some(res) => Ok(res),
|
||||
None => return Err(Status::NoContent)
|
||||
}
|
||||
}
|
||||
None => String::from("")
|
||||
None => return Err(Status::NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue