use model::v2::*; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("")] CreateProductVariant, } pub type Result = std::result::Result; #[derive(Debug)] pub struct CreateProductVariant { pub product_id: ProductId, pub name: ProductName, pub short_description: ProductShortDesc, pub long_description: ProductLongDesc, pub price: Price, } impl CreateProductVariant { pub async fn run( self, pool: &mut sqlx::Transaction<'_, sqlx::Postgres>, ) -> Result { sqlx::query_as( r#" INSERT INTO product_variants ( product_id, name, short_description, long_description, price ) VALUES ($1, $2, $3, $4, $5) RETURNINGS id, product_id, name, short_description, long_description, price "#, ) .bind(self.product_id) .bind(self.name) .bind(self.short_description) .bind(self.long_description) .bind(self.price) .fetch_one(pool) .await .map_err(|e| { tracing::error!("{}", e); dbg!(e); Error::CreateProductVariant }) } }