feat: Whitelist extension to return user whitelisted users

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-16 15:41:02 +03:00
parent b02e2d8b4d
commit d7a63ea092
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -16,6 +16,8 @@
//! Database extension to work with the whitelist table
use std::num::{NonZeroU32, NonZeroU8};
use chrono::Utc;
use oxidetalis_core::types::PublicKey;
use oxidetalis_entities::prelude::*;
@ -40,6 +42,14 @@ pub trait WhiteListExt {
whitelister: &UserModel,
target_public_key: &PublicKey,
) -> ServerResult<()>;
/// Returns the whitelist of the user
async fn user_whitelist(
&self,
whitelister: &UserModel,
page: NonZeroU32,
page_size: NonZeroU8,
) -> ServerResult<Vec<WhitelistModel>>;
}
impl WhiteListExt for DatabaseConnection {
@ -78,4 +88,19 @@ impl WhiteListExt for DatabaseConnection {
.await?;
Ok(())
}
async fn user_whitelist(
&self,
whitelister: &UserModel,
page: NonZeroU32,
page_size: NonZeroU8,
) -> ServerResult<Vec<WhitelistModel>> {
whitelister
.find_related(WhitelistEntity)
.select()
.paginate(self, u64::from(page_size.get()))
.fetch_page(u64::from(page.get() - 1))
.await
.map_err(Into::into)
}
}