add: products api
This commit is contained in:
parent
2be2409d66
commit
cf2af1e1e9
6 changed files with 241 additions and 9 deletions
|
@ -7,6 +7,5 @@ CREATE TABLE IF NOT EXISTS products (
|
|||
likes INT NOT NULL,
|
||||
dislikes INT NOT NULL,
|
||||
product_type TEXT NOT NULL,
|
||||
stripe_id TEXT NOT NULL,
|
||||
price TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::model::{
|
||||
auth::User,
|
||||
products::Product,
|
||||
permissions::{FinePermission, SecondaryPermission},
|
||||
products::{Product, ProductPrice},
|
||||
Error, Result,
|
||||
};
|
||||
use crate::{auto_method, DataManager};
|
||||
|
@ -19,7 +19,6 @@ 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(),
|
||||
stripe_id: get!(x->8(String)),
|
||||
price: serde_json::from_str(&get!(x->9(String))).unwrap(),
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO products VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
"INSERT INTO products VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -95,7 +94,6 @@ impl DataManager {
|
|||
&0_i32,
|
||||
&0_i32,
|
||||
&serde_json::to_string(&data.product_type).unwrap(),
|
||||
&data.stripe_id,
|
||||
&serde_json::to_string(&data.price).unwrap(),
|
||||
]
|
||||
);
|
||||
|
@ -135,4 +133,8 @@ impl DataManager {
|
|||
self.0.1.remove(format!("atto.product:{}", id)).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
auto_method!(update_product_name(&str)@get_product_by_id:FinePermission::MANAGE_USERS; -> "UPDATE products SET name = $1 WHERE id = $2" --cache-key-tmpl="atto.product:{}");
|
||||
auto_method!(update_product_description(&str)@get_product_by_id:FinePermission::MANAGE_USERS; -> "UPDATE products SET description = $1 WHERE id = $2" --cache-key-tmpl="atto.product:{}");
|
||||
auto_method!(update_product_price(ProductPrice)@get_product_by_id:FinePermission::MANAGE_USERS; -> "UPDATE products SET price = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.product:{}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue