Merge branch 'master' of ssh://code.ita-prog.pl/Tsumanu/bazzar

This commit is contained in:
Adrian Woźniak 2022-11-16 13:36:37 +01:00
commit 35369215ed
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B
2 changed files with 47 additions and 5 deletions

View File

@ -6,7 +6,7 @@ pub mod create_product_variant {
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Input {
pub product_id: ProductId,
pub name: ProductName,
pub name: ProductVariantName,
pub short_description: ProductShortDesc,
pub long_description: ProductLongDesc,
pub price: Price,

View File

@ -1,16 +1,58 @@
use channels::stocks::{create_product_variant, delete_product_variant, update_product_variant};
use channels::stocks::{
create_product_variant, delete_product_variant, update_product_variant, Error,
};
use channels::AsyncClient;
use config::SharedAppConfig;
use db_utils::PgT;
use crate::begin_t;
use crate::db::Database;
pub async fn create_product_variant(
_input: create_product_variant::Input,
_db: Database,
input: create_product_variant::Input,
db: Database,
_mqtt: AsyncClient,
_config: SharedAppConfig,
) -> create_product_variant::Output {
todo!()
let mut t = begin_t!(db, Error::InternalServerError);
match inner_create_product_variant(input, &mut t).await {
Ok(res) => {
if let Err(e) = t.commit().await {
tracing::error!("{}", e);
return Err(Error::InternalServerError);
}
Ok(res)
}
Err(e) => {
t.rollback().await.map_err(|e| {
tracing::error!("{}", e);
Error::InternalServerError
})?;
Err(e)
}
}
}
async fn inner_create_product_variant(
input: create_product_variant::Input,
t: &mut PgT<'_>,
) -> create_product_variant::Output {
let dbm = crate::db::CreateProductVariant {
product_id: input.product_id,
name: input.name,
short_description: input.short_description,
long_description: input.long_description,
price: input.price,
};
match dbm.run(t).await {
Ok(variant) => Ok(create_product_variant::Details {
product_variant: variant,
}),
Err(e) => {
tracing::error!("{}", e);
Err(Error::CreateProductVariant(input.product_id))
}
}
}
pub async fn update_product_variant(