mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can search for user with a given virtual directory
This commit is contained in:
parent
cadc80c24f
commit
a934d2bf82
@ -11,4 +11,5 @@ pub mod http_error;
|
||||
pub mod login_success;
|
||||
pub mod current_user_id;
|
||||
pub mod user_info;
|
||||
pub mod custom_emoji;
|
||||
pub mod custom_emoji;
|
||||
pub mod res_find_user_by_virtual_directory;
|
22
src/api_data/res_find_user_by_virtual_directory.rs
Normal file
22
src/api_data/res_find_user_by_virtual_directory.rs
Normal file
@ -0,0 +1,22 @@
|
||||
//! API output of finding user by virtual directory
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::data::user::UserID;
|
||||
use serde::Serialize;
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct FindUserByVirtualDirectoryAPIResult {
|
||||
userID: u64
|
||||
}
|
||||
|
||||
impl FindUserByVirtualDirectoryAPIResult {
|
||||
/// Construct a new `FindUserByVirtualDirectoryAPIResult` instance
|
||||
pub fn new(user_id: UserID) -> FindUserByVirtualDirectoryAPIResult {
|
||||
FindUserByVirtualDirectoryAPIResult {
|
||||
userID: user_id as u64
|
||||
}
|
||||
}
|
||||
}
|
@ -4,11 +4,17 @@
|
||||
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::helpers::user_helper;
|
||||
use crate::api_data::res_find_user_by_virtual_directory::FindUserByVirtualDirectoryAPIResult;
|
||||
|
||||
/// Find a user by its virtual directory
|
||||
pub fn find_user(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
let directory = r.post_virtual_directory("subfolder")?;
|
||||
|
||||
r.success("implement it")
|
||||
let user = r.ok_or_not_found(
|
||||
user_helper::find_user_by_virtual_directory(&directory),
|
||||
"No user was found with this subfolder!"
|
||||
)?;
|
||||
|
||||
r.set_response(FindUserByVirtualDirectoryAPIResult::new(user.id))
|
||||
}
|
@ -21,6 +21,12 @@ pub fn find_user_by_email(email: &str) -> ResultBoxError<User> {
|
||||
database::QueryInfo::new(USERS_TABLE).cond("mail", email))
|
||||
}
|
||||
|
||||
/// Get & return information about a user based on his virtual directory
|
||||
pub fn find_user_by_virtual_directory(dir: &str) -> ResultBoxError<User> {
|
||||
exec_get_user_query(
|
||||
database::QueryInfo::new(USERS_TABLE).cond("sous_repertoire", dir))
|
||||
}
|
||||
|
||||
/// Execute query & return result
|
||||
fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
||||
database::query_row(query, |res| {
|
||||
|
Loading…
Reference in New Issue
Block a user