mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-25 23:09:22 +00:00
Replace get_members_info with a more appropriate route
This commit is contained in:
parent
f34310733a
commit
92787dbb4d
@ -1,26 +0,0 @@
|
||||
//! #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<Self> {
|
||||
Ok(Self {
|
||||
user: APIUserInfo::new_advanced_info(&Some(request_from.clone()), user)?,
|
||||
membership: GroupMemberAPI::new(membership),
|
||||
})
|
||||
}
|
||||
}
|
@ -71,4 +71,3 @@ 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;
|
||||
pub mod forez_member_api;
|
@ -5,8 +5,8 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::api_data::forez_member_api::ForezMemberAPI;
|
||||
use crate::api_data::group_api::GroupApi;
|
||||
use crate::api_data::user_info::APIUserInfo;
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::config::conf;
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
@ -27,18 +27,18 @@ pub fn get_list_groups(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// Get advanced information about all the members of a group
|
||||
pub fn get_members_info(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub fn get_member_info(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let group = r.post_forez_group("group")?;
|
||||
let member = r.post_user_id("user")?;
|
||||
|
||||
let members = groups_helper::get_list_members(&group)?;
|
||||
let mut users = vec![];
|
||||
let membership = groups_helper::get_membership(&group, Some(member.clone()))?;
|
||||
|
||||
for member in members {
|
||||
let user = user_helper::find_user_by_id(&member.user_id)?;
|
||||
users.push(ForezMemberAPI::new(&user, &member, r.user_id()?)?);
|
||||
if !membership.is_at_least_member() {
|
||||
r.bad_request("This user is not a member of the group yet!".to_string())?;
|
||||
}
|
||||
|
||||
r.set_response(users)
|
||||
let user = user_helper::find_user_by_id(&member)?;
|
||||
r.set_response(APIUserInfo::new_advanced_info(&Some(member), &user)?)
|
||||
}
|
||||
|
||||
/// Set presence
|
||||
|
@ -69,6 +69,10 @@ impl GroupMember {
|
||||
pub fn is_moderator(&self) -> bool {
|
||||
self.level <= GroupMembershipLevel::MODERATOR
|
||||
}
|
||||
|
||||
pub fn is_at_least_member(&self) -> bool {
|
||||
self.level <= GroupMembershipLevel::MEMBER
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -300,6 +300,6 @@ pub fn get_routes() -> Vec<Route> {
|
||||
|
||||
// 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)),
|
||||
Route::post("/forez/get_member_info", Box::new(forez_controller::get_member_info)),
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user