feat: Whitelist extension to return user whitelisted users
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
b02e2d8b4d
commit
d7a63ea092
1 changed files with 25 additions and 0 deletions
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
//! Database extension to work with the whitelist table
|
//! Database extension to work with the whitelist table
|
||||||
|
|
||||||
|
use std::num::{NonZeroU32, NonZeroU8};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use oxidetalis_core::types::PublicKey;
|
use oxidetalis_core::types::PublicKey;
|
||||||
use oxidetalis_entities::prelude::*;
|
use oxidetalis_entities::prelude::*;
|
||||||
|
@ -40,6 +42,14 @@ pub trait WhiteListExt {
|
||||||
whitelister: &UserModel,
|
whitelister: &UserModel,
|
||||||
target_public_key: &PublicKey,
|
target_public_key: &PublicKey,
|
||||||
) -> ServerResult<()>;
|
) -> 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 {
|
impl WhiteListExt for DatabaseConnection {
|
||||||
|
@ -78,4 +88,19 @@ impl WhiteListExt for DatabaseConnection {
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue