diff --git a/src/api_data/forez_member_api.rs b/src/api_data/forez_member_api.rs new file mode 100644 index 0000000..bfb990b --- /dev/null +++ b/src/api_data/forez_member_api.rs @@ -0,0 +1,26 @@ +//! #Forez member information +//! +//! @author Pierre Hubert + +use serde::Serialize; + +use crate::api_data::group_member_api::GroupMemberAPI; +use crate::api_data::user_info::{APIAdvancedInfo, APIUserInfo}; +use crate::data::error::Res; +use crate::data::group_member::GroupMember; +use crate::data::user::{User, UserID}; + +#[derive(Serialize)] +pub struct ForezMemberAPI { + user: APIAdvancedInfo, + membership: GroupMemberAPI, +} + +impl ForezMemberAPI { + pub fn new(user: &User, membership: &GroupMember, request_from: UserID) -> Res { + Ok(Self { + user: APIUserInfo::new_advanced_info(&Some(request_from.clone()), user)?, + membership: GroupMemberAPI::new(membership), + }) + } +} \ No newline at end of file diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index a61204a..7ee7962 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -70,4 +70,5 @@ pub mod removed_user_from_conv_message; pub mod user_is_writing_message_in_conversation; pub mod res_create_conversation_for_group; pub mod notification_settings_api; -pub mod push_notifications_status_api; \ No newline at end of file +pub mod push_notifications_status_api; +pub mod forez_member_api; \ No newline at end of file diff --git a/src/controllers/forez_controller.rs b/src/controllers/forez_controller.rs index ebeb7a0..2fc0398 100644 --- a/src/controllers/forez_controller.rs +++ b/src/controllers/forez_controller.rs @@ -5,13 +5,14 @@ //! //! @author Pierre Hubert +use crate::api_data::forez_member_api::ForezMemberAPI; use crate::api_data::group_api::GroupApi; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::config::conf; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::presence::Presence; use crate::data::user_ws_request_handler::UserWsRequestHandler; -use crate::helpers::{forez_presence_helper, groups_helper}; +use crate::helpers::{forez_presence_helper, groups_helper, user_helper}; use crate::routes::RequestResult; /// Get the list of declared Forez groups in the application @@ -25,6 +26,21 @@ pub fn get_list_groups(r: &mut HttpRequestHandler) -> RequestResult { r.set_response(list) } +/// Get advanced information about all the members of a group +pub fn get_members_info(r: &mut HttpRequestHandler) -> RequestResult { + let group = r.post_forez_group("group")?; + + let members = groups_helper::get_list_members(&group)?; + let mut users = vec![]; + + for member in members { + let user = user_helper::find_user_by_id(&member.user_id)?; + users.push(ForezMemberAPI::new(&user, &member, r.user_id()?)?); + } + + r.set_response(users) +} + /// Set presence /// /// Presences format: YYYY,MM,DD;YYYY,MM,DD;... diff --git a/src/routes.rs b/src/routes.rs index fbffd81..a6a01df 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -300,5 +300,6 @@ pub fn get_routes() -> Vec { // Forez controller Route::post("/forez/get_groups", Box::new(forez_controller::get_list_groups)), + Route::post("/forez/get_members_info", Box::new(forez_controller::get_members_info)), ] } \ No newline at end of file