feat: Chat request implementation #14
1 changed files with 25 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue