1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Can search for user with a given virtual directory

This commit is contained in:
Pierre HUBERT 2020-06-02 13:26:12 +02:00
parent cadc80c24f
commit a934d2bf82
4 changed files with 38 additions and 3 deletions

View File

@ -12,3 +12,4 @@ pub mod login_success;
pub mod current_user_id;
pub mod user_info;
pub mod custom_emoji;
pub mod res_find_user_by_virtual_directory;

View 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
}
}
}

View File

@ -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))
}

View File

@ -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| {