mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-30 22:13:01 +00:00
Can get a user id included in a POST request
This commit is contained in:
parent
8e2a4a8b71
commit
cf2d9606d9
@ -48,5 +48,8 @@ pub fn get_multiple(request: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
/// Get advanced information about a user
|
/// Get advanced information about a user
|
||||||
pub fn get_advanced_info(request: &mut HttpRequestHandler) -> RequestResult {
|
pub fn get_advanced_info(request: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let user_id = request.post_user_id("userID")?;
|
||||||
|
|
||||||
|
|
||||||
request.success("get user info")
|
request.success("get user info")
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ use crate::data::api_client::APIClient;
|
|||||||
use crate::data::config::conf;
|
use crate::data::config::conf;
|
||||||
use crate::data::error::{ExecError, ResultBoxError};
|
use crate::data::error::{ExecError, ResultBoxError};
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::{account_helper, api_helper};
|
use crate::helpers::{account_helper, api_helper, user_helper};
|
||||||
|
|
||||||
/// Http request handler
|
/// Http request handler
|
||||||
///
|
///
|
||||||
@ -303,4 +303,19 @@ impl HttpRequestHandler {
|
|||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the ID of a user included in a POST request
|
||||||
|
pub fn post_user_id(&mut self, name: &str) -> ResultBoxError<UserID> {
|
||||||
|
let user_id = self.post_i64(name)?;
|
||||||
|
|
||||||
|
if user_id < 1 {
|
||||||
|
self.bad_request(format!("Invalid user specified in '{}'!", name))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !user_helper::exists(user_id)? {
|
||||||
|
self.not_found(format!("User with ID {} not found!", user_id))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(user_id)
|
||||||
|
}
|
||||||
}
|
}
|
@ -107,6 +107,11 @@ impl QueryInfo {
|
|||||||
-> Result<Vec<E>, Box<dyn Error>> {
|
-> Result<Vec<E>, Box<dyn Error>> {
|
||||||
query(self, process_function)
|
query(self, process_function)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Execute count query
|
||||||
|
pub fn exec_count(self) -> ResultBoxError<usize> {
|
||||||
|
count(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Struct used to read the result of a request
|
/// Struct used to read the result of a request
|
||||||
|
@ -53,3 +53,10 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check out whether a given id maps to a user or not
|
||||||
|
pub fn exists(id: UserID) -> ResultBoxError<bool> {
|
||||||
|
Ok(database::QueryInfo::new(USERS_TABLE)
|
||||||
|
.cond_i64("ID", id)
|
||||||
|
.exec_count()? > 0)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user