add: post image uploads (supporter)

This commit is contained in:
trisua 2025-05-11 14:27:55 -04:00
parent ba1f8ef063
commit 70965298b5
18 changed files with 455 additions and 50 deletions

View file

@ -10,5 +10,7 @@ CREATE TABLE IF NOT EXISTS posts (
likes INT NOT NULL,
dislikes INT NOT NULL,
-- other counts
comment_count INT NOT NULL
comment_count INT NOT NULL,
-- ...
uploads TEXT NOT NULL
)

View file

@ -1,5 +1,4 @@
use std::collections::HashMap;
use super::*;
use crate::cache::Cache;
use crate::model::{

View file

@ -250,7 +250,7 @@ impl DataManager {
}
/// Delete a membership given its `id`
pub async fn delete_membership(&self, id: usize, user: User) -> Result<()> {
pub async fn delete_membership(&self, id: usize, user: &User) -> Result<()> {
let y = self.get_membership_by_id(id).await?;
if user.id != y.owner {

View file

@ -41,6 +41,8 @@ impl DataManager {
dislikes: get!(x->8(i32)) as isize,
// other counts
comment_count: get!(x->9(i32)) as usize,
// ...
uploads: serde_json::from_str(&get!(x->10(String))).unwrap(),
}
}
@ -1038,7 +1040,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
"INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
params![
&(data.id as i64),
&(data.created as i64),
@ -1053,7 +1055,8 @@ impl DataManager {
},
&0_i32,
&0_i32,
&0_i32
&0_i32,
&serde_json::to_string(&data.uploads).unwrap()
]
);
@ -1148,6 +1151,11 @@ impl DataManager {
}
}
// delete uploads
for upload in y.uploads {
self.delete_upload(upload).await?;
}
// return
Ok(())
}

View file

@ -236,6 +236,8 @@ pub struct Post {
pub likes: isize,
pub dislikes: isize,
pub comment_count: usize,
/// IDs of all uploads linked to this post.
pub uploads: Vec<usize>,
}
impl Post {
@ -257,6 +259,7 @@ impl Post {
likes: 0,
dislikes: 0,
comment_count: 0,
uploads: Vec::new(),
}
}