add: product uploads

This commit is contained in:
trisua 2025-07-13 23:15:00 -04:00
parent 292d302304
commit 3b5b0ce1a1
8 changed files with 27 additions and 7 deletions

View file

@ -7,5 +7,6 @@ CREATE TABLE IF NOT EXISTS products (
likes INT NOT NULL,
dislikes INT NOT NULL,
product_type TEXT NOT NULL,
price TEXT NOT NULL
price TEXT NOT NULL,
uploads TEXT NOT NULL
)

View file

@ -19,7 +19,8 @@ impl DataManager {
likes: get!(x->5(i32)) as isize,
dislikes: get!(x->6(i32)) as isize,
product_type: serde_json::from_str(&get!(x->7(String))).unwrap(),
price: serde_json::from_str(&get!(x->9(String))).unwrap(),
price: serde_json::from_str(&get!(x->8(String))).unwrap(),
uploads: serde_json::from_str(&get!(x->9(String))).unwrap(),
}
}
@ -84,7 +85,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO products VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
"INSERT INTO products VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
params![
&(data.id as i64),
&(data.created as i64),
@ -95,6 +96,7 @@ impl DataManager {
&0_i32,
&serde_json::to_string(&data.product_type).unwrap(),
&serde_json::to_string(&data.price).unwrap(),
&serde_json::to_string(&data.uploads).unwrap(),
]
);

View file

@ -45,7 +45,11 @@ impl DataManager {
question: &Question,
) -> Result<Option<(User, Post)>> {
Ok(if let Some(id) = question.context.asking_about {
let post = self.get_post_by_id(id).await?;
let post = match self.get_post_by_id(id).await {
Ok(x) => x,
Err(_) => return Ok(None),
};
Some((self.get_user_by_id(post.owner).await?, post))
} else {
None

View file

@ -14,6 +14,8 @@ pub struct Product {
pub dislikes: isize,
pub product_type: ProductType,
pub price: ProductPrice,
/// Optional uploads to accompany the product title and description. Maximum of 4.
pub uploads: Vec<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -80,6 +82,7 @@ impl Product {
dislikes: 0,
product_type: r#type,
price,
uploads: Vec::new(),
}
}
}