add: community member list
This commit is contained in:
parent
1a2efdba1f
commit
ca0c4b9e0b
12 changed files with 264 additions and 16 deletions
|
@ -43,6 +43,19 @@ impl DataManager {
|
|||
Ok(communities)
|
||||
}
|
||||
|
||||
/// Replace a list of community memberships with the proper user.
|
||||
pub async fn fill_users(
|
||||
&self,
|
||||
list: Vec<CommunityMembership>,
|
||||
) -> Result<Vec<(CommunityMembership, User)>> {
|
||||
let mut users: Vec<(CommunityMembership, User)> = Vec::new();
|
||||
for membership in list {
|
||||
let owner = membership.owner.clone();
|
||||
users.push((membership, self.get_user_by_id(owner).await?));
|
||||
}
|
||||
Ok(users)
|
||||
}
|
||||
|
||||
/// Get a community membership by `owner` and `community`.
|
||||
pub async fn get_membership_by_owner_community(
|
||||
&self,
|
||||
|
@ -90,6 +103,37 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all community memberships by `community`.
|
||||
pub async fn get_memberships_by_community(
|
||||
&self,
|
||||
community: usize,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<CommunityMembership>> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
// 33 = banned, 65 = pending membership
|
||||
"SELECT * FROM memberships WHERE community = $1 AND NOT role = 33 AND NOT role = 65 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
&[
|
||||
&(community as i64),
|
||||
&(batch as i64),
|
||||
&((page * batch) as i64)
|
||||
],
|
||||
|x| { Self::get_membership_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("community membership".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new community membership in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -16,6 +16,7 @@ bitflags! {
|
|||
const BANNED = 1 << 5;
|
||||
const REQUESTED = 1 << 6;
|
||||
const MANAGE_PINS = 1 << 7;
|
||||
const MANAGE_COMMUNITY = 1 << 8;
|
||||
|
||||
const _ = !0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue