From d7a63ea0922bd6dfe9494a018cffeca442034c0e Mon Sep 17 00:00:00 2001 From: Awiteb Date: Tue, 16 Jul 2024 15:41:02 +0300 Subject: [PATCH] feat: Whitelist extension to return user whitelisted users Signed-off-by: Awiteb --- crates/oxidetalis/src/database/whitelist.rs | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/oxidetalis/src/database/whitelist.rs b/crates/oxidetalis/src/database/whitelist.rs index 370407e..e09f6e0 100644 --- a/crates/oxidetalis/src/database/whitelist.rs +++ b/crates/oxidetalis/src/database/whitelist.rs @@ -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>; } 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> { + whitelister + .find_related(WhitelistEntity) + .select() + .paginate(self, u64::from(page_size.get())) + .fetch_page(u64::from(page.get() - 1)) + .await + .map_err(Into::into) + } }