1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can get information about multiple groups

This commit is contained in:
Pierre HUBERT 2020-06-25 09:26:58 +02:00
parent aacf87cf40
commit 444cad6e09
3 changed files with 29 additions and 2 deletions

View File

@ -2,13 +2,16 @@
//! //!
//! @author Pierre Hubert //! @author Pierre Hubert
use std::collections::HashMap;
use crate::api_data::group_api::GroupApi;
use crate::api_data::res_create_group::GroupCreationResult; use crate::api_data::res_create_group::GroupCreationResult;
use crate::controllers::routes::RequestResult; use crate::controllers::routes::RequestResult;
use crate::data::group::GroupAccessLevel; use crate::data::group::GroupAccessLevel;
use crate::data::group_id::GroupID;
use crate::data::http_request_handler::HttpRequestHandler; use crate::data::http_request_handler::HttpRequestHandler;
use crate::data::new_group::NewGroup; use crate::data::new_group::NewGroup;
use crate::helpers::groups_helper; use crate::helpers::groups_helper;
use crate::api_data::group_api::GroupApi;
/// Create a new group /// Create a new group
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
@ -39,3 +42,25 @@ pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
r.set_response(GroupApi::new(&group, r.user_id_opt())?) r.set_response(GroupApi::new(&group, r.user_id_opt())?)
} }
/// Get information about multiple users
pub fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult {
let groups_id = r.post_numbers_list("list", 1)?;
let mut list = HashMap::new();
for id in groups_id {
let id = GroupID::new(id as u64);
if !groups_helper::exists(&id)? ||
groups_helper::get_access_level(&id, r.user_id_opt())? < GroupAccessLevel::LIMITED_ACCESS {
r.not_found(format!("Group {} not found!", id.id()))?;
}
let group = groups_helper::get_info(&id)?;
list.insert(id.id().to_string(), GroupApi::new(&group, r.user_id_opt())?);
}
r.set_response(list)
}

View File

@ -134,6 +134,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/groups/get_info", Box::new(groups_controller::get_info_single)), Route::post("/groups/get_info", Box::new(groups_controller::get_info_single)),
Route::post("/groups/get_multiple_info", Box::new(groups_controller::get_info_multiple)),
// Virtual directory controller // Virtual directory controller
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)), Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),

View File

@ -9,6 +9,6 @@ pub struct NewConversation {
pub owner_id: UserID, pub owner_id: UserID,
pub name: Option<String>, pub name: Option<String>,
pub owner_following: bool, pub owner_following: bool,
pub members: Vec<i64>, pub members: Vec<UserID>,
pub can_everyone_add_members: bool pub can_everyone_add_members: bool
} }