mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 09:34:04 +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)?,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -25,3 +25,4 @@ pub mod list_unread_conversations_api;
 | 
			
		||||
pub mod global_search_result_api;
 | 
			
		||||
pub mod res_create_group;
 | 
			
		||||
pub mod group_api;
 | 
			
		||||
pub mod advanced_group_api;
 | 
			
		||||
@@ -12,6 +12,7 @@ use crate::data::group_id::GroupID;
 | 
			
		||||
use crate::data::http_request_handler::HttpRequestHandler;
 | 
			
		||||
use crate::data::new_group::NewGroup;
 | 
			
		||||
use crate::helpers::groups_helper;
 | 
			
		||||
use crate::api_data::advanced_group_api::AdvancedGroupApi;
 | 
			
		||||
 | 
			
		||||
/// Create a new group
 | 
			
		||||
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
 | 
			
		||||
@@ -64,3 +65,11 @@ pub fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult {
 | 
			
		||||
 | 
			
		||||
    r.set_response(list)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get advanced information about a user
 | 
			
		||||
pub fn get_advanced_info(r: &mut HttpRequestHandler) -> RequestResult {
 | 
			
		||||
    let group_id = r.post_group_id_with_access("id", GroupAccessLevel::VIEW_ACCESS)?;
 | 
			
		||||
    let group = groups_helper::get_info(&group_id)?;
 | 
			
		||||
 | 
			
		||||
    r.set_response(AdvancedGroupApi::new(&group, r.user_id_opt())?)
 | 
			
		||||
}
 | 
			
		||||
@@ -136,6 +136,8 @@ pub fn get_routes() -> Vec<Route> {
 | 
			
		||||
 | 
			
		||||
        Route::post("/groups/get_multiple_info", Box::new(groups_controller::get_info_multiple)),
 | 
			
		||||
 | 
			
		||||
        Route::post("/groups/get_advanced_info", Box::new(groups_controller::get_advanced_info)),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        // Virtual directory controller
 | 
			
		||||
        Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,11 @@ impl UserID {
 | 
			
		||||
        UserID(id)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Create a new invalid user id
 | 
			
		||||
    pub fn invalid() -> UserID {
 | 
			
		||||
        UserID(0)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get the current ID stored in this structure
 | 
			
		||||
    pub fn id(&self) -> u64 {
 | 
			
		||||
        self.0
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user