mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-15 15:07:43 +00:00
Get the list of groups of a user
This commit is contained in:
parent
5a14aaee31
commit
c245045d67
@ -18,4 +18,14 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let group_id = groups_helper::create(&new_group)?;
|
||||
|
||||
r.set_response(GroupCreationResult::new(&group_id))
|
||||
}
|
||||
|
||||
/// Get the list of groups of the current user
|
||||
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let list = groups_helper::get_list_user(r.user_id()?, false)?
|
||||
.iter()
|
||||
.map(|f| f.id())
|
||||
.collect::<Vec<u64>>();
|
||||
|
||||
r.set_response(list)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use std::error::Error;
|
||||
|
||||
use crate::controllers::{account_controller, conversations_controller, search_controller, server_controller, user_controller, virtual_directory_controller, groups_controller};
|
||||
use crate::controllers::{account_controller, conversations_controller, groups_controller, search_controller, server_controller, user_controller, virtual_directory_controller};
|
||||
use crate::controllers::routes::Method::{GET, POST};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
|
||||
@ -130,6 +130,8 @@ pub fn get_routes() -> Vec<Route> {
|
||||
// Groups controller
|
||||
Route::post("/groups/create", Box::new(groups_controller::create)),
|
||||
|
||||
Route::post("/groups/get_my_list", Box::new(groups_controller::get_list_user)),
|
||||
|
||||
|
||||
// Virtual directory controller
|
||||
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
||||
|
@ -8,6 +8,7 @@ use crate::data::group::GroupVisibilityLevel;
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||
use crate::data::new_group::NewGroup;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::database;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
@ -67,6 +68,19 @@ pub fn insert_member(m: &GroupMember) -> ResultBoxError<()> {
|
||||
.insert_drop_result()
|
||||
}
|
||||
|
||||
/// Get the list of groups of a user
|
||||
pub fn get_list_user(user_id: UserID, only_followed: bool) -> ResultBoxError<Vec<GroupID>> {
|
||||
let mut query = database::QueryInfo::new(GROUPS_MEMBERS_TABLE)
|
||||
.add_field("groups_id")
|
||||
.cond_user_id("user_id", user_id);
|
||||
|
||||
if only_followed {
|
||||
query = query.cond_legacy_bool("following", true);
|
||||
}
|
||||
|
||||
query.exec(|row| row.get_group_id("groups_id"))
|
||||
}
|
||||
|
||||
/// Find a group id by virtual directory
|
||||
pub fn find_by_virtual_directory(dir: &str) -> ResultBoxError<GroupID> {
|
||||
database::QueryInfo::new(GROUPS_LIST_TABLE)
|
||||
|
Loading…
Reference in New Issue
Block a user