mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-20 11:58:47 +00:00
Can get advanced information about a group
This commit is contained in:
37
src/api_data/advanced_group_api.rs
Normal file
37
src/api_data/advanced_group_api.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
//! # Advanced group information
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::group_api::GroupApi;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::group::Group;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::likes_helper;
|
||||
use crate::helpers::likes_helper::LikeType;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AdvancedGroupApi {
|
||||
#[serde(flatten)]
|
||||
base_info: GroupApi,
|
||||
|
||||
time_create: u64,
|
||||
description: String,
|
||||
url: String,
|
||||
number_likes: u64,
|
||||
is_liking: bool,
|
||||
}
|
||||
|
||||
impl AdvancedGroupApi {
|
||||
/// Construct a new advanced group membership instance
|
||||
pub fn new(g: &Group, user_id: Option<UserID>) -> ResultBoxError<AdvancedGroupApi> {
|
||||
Ok(AdvancedGroupApi {
|
||||
base_info: GroupApi::new(g, user_id.clone())?,
|
||||
time_create: g.time_create,
|
||||
description: g.description.clone().unwrap_or("null".to_string()),
|
||||
url: g.url.clone().unwrap_or("null".to_string()),
|
||||
number_likes: likes_helper::count(g.id.id(), LikeType::GROUP)? as u64,
|
||||
is_liking: likes_helper::is_liking(&user_id.unwrap_or(UserID::invalid()), g.id.id(), LikeType::GROUP)?,
|
||||
})
|
||||
}
|
||||
}
|
@@ -24,4 +24,5 @@ pub mod res_count_unread_conversations;
|
||||
pub mod list_unread_conversations_api;
|
||||
pub mod global_search_result_api;
|
||||
pub mod res_create_group;
|
||||
pub mod group_api;
|
||||
pub mod group_api;
|
||||
pub mod advanced_group_api;
|
Reference in New Issue
Block a user