mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can get the list of members of a group
This commit is contained in:
parent
ef532f5900
commit
d7608ec974
32
src/api_data/group_member_api.rs
Normal file
32
src/api_data/group_member_api.rs
Normal file
@ -0,0 +1,32 @@
|
||||
//! # Group member API entry
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::group_member::GroupMember;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct GroupMemberAPI {
|
||||
user_id: u64,
|
||||
group_id: u64,
|
||||
time_create: u64,
|
||||
level: String,
|
||||
}
|
||||
|
||||
impl GroupMemberAPI {
|
||||
/// Turn a `GroupMember` object into an API entry
|
||||
pub fn new(g: &GroupMember) -> GroupMemberAPI {
|
||||
GroupMemberAPI {
|
||||
user_id: g.user_id.id(),
|
||||
group_id: g.group_id.id(),
|
||||
time_create: g.time_create,
|
||||
level: g.level.to_api(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Turn a list of GroupMember object into API entries
|
||||
pub fn for_list(l: &Vec<GroupMember>) -> Vec<GroupMemberAPI> {
|
||||
l.iter().map(Self::new).collect()
|
||||
}
|
||||
}
|
@ -27,3 +27,4 @@ pub mod res_create_group;
|
||||
pub mod group_api;
|
||||
pub mod advanced_group_api;
|
||||
pub mod res_change_group_logo;
|
||||
pub mod group_member_api;
|
@ -6,6 +6,7 @@ use std::collections::HashMap;
|
||||
|
||||
use crate::api_data::advanced_group_api::AdvancedGroupApi;
|
||||
use crate::api_data::group_api::GroupApi;
|
||||
use crate::api_data::group_member_api::GroupMemberAPI;
|
||||
use crate::api_data::res_change_group_logo::ResChangeGroupLogo;
|
||||
use crate::api_data::res_create_group::GroupCreationResult;
|
||||
use crate::constants::{DEFAULT_GROUP_LOGO, PATH_GROUPS_LOGOS};
|
||||
@ -149,5 +150,9 @@ pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
/// Get the list of members of a group
|
||||
pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.success("implement me")
|
||||
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::MODERATOR_ACCESS)?;
|
||||
|
||||
let members = groups_helper::get_list_members(&group_id)?;
|
||||
|
||||
r.set_response(GroupMemberAPI::for_list(&members))
|
||||
}
|
@ -324,6 +324,13 @@ pub fn delete_logo(g: &GroupID) -> ResultBoxError {
|
||||
set_logo_path(g, None)
|
||||
}
|
||||
|
||||
/// Get the list of memberships of a group
|
||||
pub fn get_list_members(g: &GroupID) -> ResultBoxError<Vec<GroupMember>> {
|
||||
database::QueryInfo::new(GROUPS_MEMBERS_TABLE)
|
||||
.cond_group_id("groups_id", g)
|
||||
.exec(db_to_group_member)
|
||||
}
|
||||
|
||||
/// Turn a database entry into a group struct
|
||||
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
|
||||
let group_id = row.get_group_id("id")?;
|
||||
|
Loading…
Reference in New Issue
Block a user