add: post likes page

fix: requests pkey
This commit is contained in:
trisua 2025-05-14 19:54:53 -04:00
parent bbb629336f
commit b63df2cb31
11 changed files with 274 additions and 14 deletions

View file

@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS requests (
created BIGINT NOT NULL,
owner BIGINT NOT NULL,
action_type TEXT NOT NULL,
linked_asset BIGINT NOT NULL
linked_asset BIGINT NOT NULL,
PRIMARY KEY (id, owner, linked_asset)
)

View file

@ -6,7 +6,7 @@ use crate::model::{
permissions::FinePermission,
reactions::{AssetType, Reaction},
};
use crate::{auto_method, execute, get, query_row, params};
use crate::{auto_method, execute, get, params, query_row, query_rows};
#[cfg(feature = "sqlite")]
use rusqlite::Row;
@ -32,6 +32,51 @@ impl DataManager {
auto_method!(get_reaction_by_id()@get_reaction_from_row -> "SELECT * FROM reactions WHERE id = $1" --name="reaction" --returns=Reaction --cache-key-tmpl="atto.reaction:{}");
/// Get all owner profiles from a reactions list.
pub async fn fill_reactions(
&self,
reactions: &Vec<Reaction>,
ignore_users: Vec<usize>,
) -> Result<Vec<User>> {
let mut out = Vec::new();
for reaction in reactions {
if ignore_users.contains(&reaction.owner) {
continue;
}
out.push(self.get_user_by_id(reaction.owner.to_owned()).await?);
}
Ok(out)
}
/// Get a reaction by `owner` and `asset`.
pub async fn get_reactions_by_asset(
&self,
asset: usize,
batch: usize,
page: usize,
) -> Result<Vec<Reaction>> {
let conn = match self.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = query_rows!(
&conn,
"SELECT * FROM reactions WHERE asset = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
&[&(asset as i64), &(batch as i64), &((page * batch) as i64)],
|x| { Self::get_reaction_from_row(x) }
);
if res.is_err() {
return Err(Error::GeneralNotFound("reaction".to_string()));
}
Ok(res.unwrap())
}
/// Get a reaction by `owner` and `asset`.
pub async fn get_reaction_by_owner_asset(
&self,