mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can make global search
This commit is contained in:
@ -11,6 +11,7 @@ use mysql::prelude::Queryable;
|
||||
use crate::data::config::DatabaseConfig;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::group_id::GroupID;
|
||||
|
||||
/// Database access helper
|
||||
///
|
||||
@ -271,6 +272,11 @@ impl<'a> RowResult<'a> {
|
||||
self.get_int64(name)
|
||||
}
|
||||
|
||||
/// Get the ID of a group included in the response
|
||||
pub fn get_group_id(&self, name: &str) -> ResultBoxError<GroupID> {
|
||||
Ok(GroupID::new(self.get_u64(name)?))
|
||||
}
|
||||
|
||||
/// Find a string included in the request
|
||||
pub fn get_str(&self, name: &str) -> Result<String, Box<dyn Error>> {
|
||||
let value = self.row.get_opt(self.find_col(name)?);
|
||||
|
@ -2,9 +2,21 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::helpers::database;
|
||||
use crate::constants::database_tables_names::GROUPS_LIST_TABLE;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::group::GroupVisibilityLevel;
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::helpers::database;
|
||||
|
||||
impl GroupVisibilityLevel {
|
||||
pub fn to_db(&self) -> u64 {
|
||||
match self {
|
||||
GroupVisibilityLevel::OPEN_GROUP => 0,
|
||||
GroupVisibilityLevel::PRIVATE_GROUP => 1,
|
||||
GroupVisibilityLevel::SECRETE_GROUP => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Find a group id by virtual directory
|
||||
pub fn find_by_virtual_directory(dir: &str) -> ResultBoxError<u64> {
|
||||
@ -12,4 +24,15 @@ pub fn find_by_virtual_directory(dir: &str) -> ResultBoxError<u64> {
|
||||
.cond("virtual_directory", dir)
|
||||
.add_field("id")
|
||||
.query_row(|res| res.get_u64("id"))
|
||||
}
|
||||
|
||||
/// Search for group
|
||||
pub fn search_group(query: &str, limit: u64) -> ResultBoxError<Vec<GroupID>> {
|
||||
database::QueryInfo::new(GROUPS_LIST_TABLE)
|
||||
.set_custom_where("name LIKE ? AND visibility != ?")
|
||||
.add_custom_where_argument_str(format!("%{}%", query).as_str())
|
||||
.add_custom_where_argument_u64(GroupVisibilityLevel::SECRETE_GROUP.to_db())
|
||||
.set_limit(limit)
|
||||
.add_field("id")
|
||||
.exec(|row| row.get_group_id("id"))
|
||||
}
|
Reference in New Issue
Block a user