mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can get information about multiple users
This commit is contained in:
@ -137,6 +137,18 @@ impl HttpRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/// If result is not OK, return a 404 not found error
|
||||
pub fn ok_or_not_found<E>(&mut self, res: ResultBoxError<E>, msg: &str) -> ResultBoxError<E> {
|
||||
match res {
|
||||
Ok(e) => Ok(e),
|
||||
Err(err) => {
|
||||
println!("Error leading to 404 not found: {}", err);
|
||||
self.not_found(msg.to_string())?;
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the path of the request
|
||||
pub fn request_path(&self) -> String {
|
||||
self.request.path().to_string()
|
||||
@ -271,4 +283,24 @@ impl HttpRequestHandler {
|
||||
|
||||
Ok(mail)
|
||||
}
|
||||
|
||||
/// Get a list of integers included in the request
|
||||
pub fn post_numbers_list(&mut self, name: &str, min_len: usize) -> ResultBoxError<Vec<i64>> {
|
||||
let param = self.post_string_opt(name, min_len, min_len != 0)?;
|
||||
let mut list = vec![];
|
||||
|
||||
for split in param.split::<&str>(",") {
|
||||
if split.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.push(split.parse::<i64>()?);
|
||||
}
|
||||
|
||||
if list.len() < min_len {
|
||||
self.bad_request(format!("Not enough entries in '{}'!", name))?;
|
||||
}
|
||||
|
||||
Ok(list)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user