mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-27 15:59:21 +00:00
41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
//! # Groups controller
|
|
//!
|
|
//! @author Pierre Hubert
|
|
|
|
use crate::api_data::res_create_group::GroupCreationResult;
|
|
use crate::controllers::routes::RequestResult;
|
|
use crate::data::group::GroupAccessLevel;
|
|
use crate::data::http_request_handler::HttpRequestHandler;
|
|
use crate::data::new_group::NewGroup;
|
|
use crate::helpers::groups_helper;
|
|
use crate::api_data::group_api::GroupApi;
|
|
|
|
/// Create a new group
|
|
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
|
let new_group = NewGroup {
|
|
name: r.post_string_opt("name", 3, true)?,
|
|
owner_id: r.user_id()?,
|
|
};
|
|
|
|
let group_id = groups_helper::create(&new_group)?;
|
|
|
|
r.set_response(GroupCreationResult::new(&group_id))
|
|
}
|
|
|
|
/// Get the list of groups of the current user
|
|
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
|
|
let list = groups_helper::get_list_user(r.user_id()?, false)?
|
|
.iter()
|
|
.map(|f| f.id())
|
|
.collect::<Vec<u64>>();
|
|
|
|
r.set_response(list)
|
|
}
|
|
|
|
/// Get information about a single group
|
|
pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
|
|
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
|
|
let group = groups_helper::get_info(&group_id)?;
|
|
|
|
r.set_response(GroupApi::new(&group, r.user_id_opt())?)
|
|
} |