add: single_use products
This commit is contained in:
parent
7fbc732290
commit
e5e6d5cddb
12 changed files with 149 additions and 7 deletions
|
@ -732,6 +732,10 @@ pub fn routes() -> Router {
|
|||
"/products/{id}/on_sale",
|
||||
post(products::update_on_sale_request),
|
||||
)
|
||||
.route(
|
||||
"/products/{id}/single_use",
|
||||
post(products::update_single_use_request),
|
||||
)
|
||||
.route("/products/{id}/price", post(products::update_price_request))
|
||||
.route(
|
||||
"/products/{id}/method",
|
||||
|
@ -1275,6 +1279,11 @@ pub struct UpdateProductOnSale {
|
|||
pub on_sale: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateProductSingleUse {
|
||||
pub single_use: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateProductPrice {
|
||||
pub price: i32,
|
||||
|
|
|
@ -3,7 +3,7 @@ use axum::{extract::Path, response::IntoResponse, Extension, Json};
|
|||
use tetratto_core::model::{economy::Product, oauth, ApiReturn, Error};
|
||||
use super::{
|
||||
CreateProduct, UpdateProductDescription, UpdateProductMethod, UpdateProductOnSale,
|
||||
UpdateProductPrice, UpdateProductStock, UpdateProductTitle,
|
||||
UpdateProductPrice, UpdateProductSingleUse, UpdateProductStock, UpdateProductTitle,
|
||||
};
|
||||
|
||||
pub async fn create_request(
|
||||
|
@ -137,6 +137,31 @@ pub async fn update_on_sale_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn update_single_use_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateProductSingleUse>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageProducts) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data
|
||||
.update_product_single_use(id, &user, if req.single_use { 1 } else { 0 })
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Product updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_price_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue