mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-27 07:49:21 +00:00
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
//! # 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)?,
|
|
})
|
|
}
|
|
} |