add: blocked users page
This commit is contained in:
parent
6893aeedb5
commit
3706764437
18 changed files with 427 additions and 178 deletions
crates/core/src/database
|
@ -25,6 +25,17 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_userblock_by_id()@get_userblock_from_row -> "SELECT * FROM userblocks WHERE id = $1" --name="user block" --returns=UserBlock --cache-key-tmpl="atto.userblock:{}");
|
||||
|
||||
/// Fill a vector of user blocks with their receivers.
|
||||
pub async fn fill_userblocks_receivers(&self, list: Vec<UserBlock>) -> Result<Vec<User>> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
for block in list {
|
||||
out.push(self.get_user_by_id(block.receiver).await?);
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Get a user block by `initiator` and `receiver` (in that order).
|
||||
pub async fn get_userblock_by_initiator_receiver(
|
||||
&self,
|
||||
|
@ -104,6 +115,28 @@ impl DataManager {
|
|||
out
|
||||
}
|
||||
|
||||
/// Get all user blocks created by the given `initiator`.
|
||||
pub async fn get_userblocks_by_initiator(&self, initiator: usize) -> Vec<UserBlock> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM userblocks WHERE initiator = $1",
|
||||
&[&(initiator as i64)],
|
||||
|x| { Self::get_userblock_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
// return
|
||||
res.unwrap()
|
||||
}
|
||||
|
||||
/// Create a new user block in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue