Add deliver days
This commit is contained in:
parent
05584144d6
commit
8871f46738
@ -4,8 +4,8 @@ use sqlx::PgPool;
|
|||||||
use super::Result;
|
use super::Result;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
PriceMajor, PriceMinor, Product, ProductCategory, ProductId, ProductLongDesc, ProductName,
|
Days, PriceMajor, PriceMinor, Product, ProductCategory, ProductId, ProductLongDesc,
|
||||||
ProductShortDesc,
|
ProductName, ProductShortDesc,
|
||||||
};
|
};
|
||||||
use crate::{database, model};
|
use crate::{database, model};
|
||||||
|
|
||||||
@ -58,6 +58,7 @@ pub struct CreateProduct {
|
|||||||
pub category: Option<ProductCategory>,
|
pub category: Option<ProductCategory>,
|
||||||
pub price_major: PriceMajor,
|
pub price_major: PriceMajor,
|
||||||
pub price_minor: PriceMinor,
|
pub price_minor: PriceMinor,
|
||||||
|
pub deliver_days_flag: Days,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::db_async_handler!(CreateProduct, create_product, Product);
|
crate::db_async_handler!(CreateProduct, create_product, Product);
|
||||||
@ -66,14 +67,15 @@ pub(crate) async fn create_product(msg: CreateProduct, pool: PgPool) -> Result<m
|
|||||||
sqlx::query_as(
|
sqlx::query_as(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO products (name, short_description, long_description, category, price_major, price_minor)
|
INSERT INTO products (name, short_description, long_description, category, price_major, price_minor)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
RETURNING id,
|
RETURNING id,
|
||||||
name,
|
name,
|
||||||
short_description,
|
short_description,
|
||||||
long_description,
|
long_description,
|
||||||
category,
|
category,
|
||||||
price_major,
|
price_major,
|
||||||
price_minor
|
price_minor,
|
||||||
|
deliver_days_flag
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(msg.name)
|
.bind(msg.name)
|
||||||
@ -82,6 +84,7 @@ RETURNING id,
|
|||||||
.bind(msg.category)
|
.bind(msg.category)
|
||||||
.bind(msg.price_major)
|
.bind(msg.price_major)
|
||||||
.bind(msg.price_minor)
|
.bind(msg.price_minor)
|
||||||
|
.bind(msg.deliver_days_flag)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
@ -100,6 +103,7 @@ pub struct UpdateProduct {
|
|||||||
pub category: Option<ProductCategory>,
|
pub category: Option<ProductCategory>,
|
||||||
pub price_major: PriceMajor,
|
pub price_major: PriceMajor,
|
||||||
pub price_minor: PriceMinor,
|
pub price_minor: PriceMinor,
|
||||||
|
pub deliver_days_flag: Days,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::db_async_handler!(UpdateProduct, update_product, Product);
|
crate::db_async_handler!(UpdateProduct, update_product, Product);
|
||||||
@ -108,29 +112,32 @@ pub(crate) async fn update_product(msg: UpdateProduct, pool: PgPool) -> Result<m
|
|||||||
sqlx::query_as(
|
sqlx::query_as(
|
||||||
r#"
|
r#"
|
||||||
UPDATE products
|
UPDATE products
|
||||||
SET name = $1 AND
|
SET name = $2 AND
|
||||||
short_description = $2 AND
|
short_description = $3 AND
|
||||||
long_description = $3 AND
|
long_description = $4 AND
|
||||||
category = $4 AND
|
category = $5 AND
|
||||||
price_major = $5 AND
|
price_major = $6 AND
|
||||||
price_minor = $6
|
price_minor = $7 AND
|
||||||
WHERE id = $7
|
deliver_days_flag = $8
|
||||||
|
WHERE id = $1
|
||||||
RETURNING id,
|
RETURNING id,
|
||||||
name,
|
name,
|
||||||
short_description,
|
short_description,
|
||||||
long_description,
|
long_description,
|
||||||
category,
|
category,
|
||||||
price_major,
|
price_major,
|
||||||
price_minor
|
price_minor,
|
||||||
|
deliver_days_flag
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
|
.bind(msg.id)
|
||||||
.bind(msg.name)
|
.bind(msg.name)
|
||||||
.bind(msg.short_description)
|
.bind(msg.short_description)
|
||||||
.bind(msg.long_description)
|
.bind(msg.long_description)
|
||||||
.bind(msg.category)
|
.bind(msg.category)
|
||||||
.bind(msg.price_major)
|
.bind(msg.price_major)
|
||||||
.bind(msg.price_minor)
|
.bind(msg.price_minor)
|
||||||
.bind(msg.id)
|
.bind(msg.deliver_days_flag)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
@ -152,6 +159,14 @@ pub(crate) async fn delete_product(msg: DeleteProduct, pool: PgPool) -> Result<O
|
|||||||
r#"
|
r#"
|
||||||
DELETE FROM products
|
DELETE FROM products
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
|
RETURNING id,
|
||||||
|
name,
|
||||||
|
short_description,
|
||||||
|
long_description,
|
||||||
|
category,
|
||||||
|
price_major,
|
||||||
|
price_minor,
|
||||||
|
deliver_days_flag
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(msg.product_id)
|
.bind(msg.product_id)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::database;
|
use crate::database;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
PriceMajor, PriceMinor, ProductCategory, ProductId, ProductLongDesc, ProductName,
|
Days, PriceMajor, PriceMinor, ProductCategory, ProductId, ProductLongDesc, ProductName,
|
||||||
ProductShortDesc,
|
ProductShortDesc,
|
||||||
};
|
};
|
||||||
use crate::routes::admin::Error;
|
use crate::routes::admin::Error;
|
||||||
@ -30,6 +30,7 @@ pub struct UpdateProduct {
|
|||||||
pub category: Option<ProductCategory>,
|
pub category: Option<ProductCategory>,
|
||||||
pub price_major: PriceMajor,
|
pub price_major: PriceMajor,
|
||||||
pub price_minor: PriceMinor,
|
pub price_minor: PriceMinor,
|
||||||
|
pub deliver_days_flag: Days,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("/product")]
|
#[patch("/product")]
|
||||||
@ -50,6 +51,7 @@ async fn update_product(
|
|||||||
category: payload.category,
|
category: payload.category,
|
||||||
price_major: payload.price_major,
|
price_major: payload.price_major,
|
||||||
price_minor: payload.price_minor,
|
price_minor: payload.price_minor,
|
||||||
|
deliver_days_flag: payload.deliver_days_flag,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -62,6 +64,7 @@ pub struct CreateProduct {
|
|||||||
pub category: Option<ProductCategory>,
|
pub category: Option<ProductCategory>,
|
||||||
pub price_major: PriceMajor,
|
pub price_major: PriceMajor,
|
||||||
pub price_minor: PriceMinor,
|
pub price_minor: PriceMinor,
|
||||||
|
pub deliver_days_flag: Days,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/product")]
|
#[post("/product")]
|
||||||
@ -81,6 +84,7 @@ async fn create_product(
|
|||||||
category: payload.category,
|
category: payload.category,
|
||||||
price_major: payload.price_major,
|
price_major: payload.price_major,
|
||||||
price_minor: payload.price_minor,
|
price_minor: payload.price_minor,
|
||||||
|
deliver_days_flag: payload.deliver_days_flag,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user