use model::v2::{ProductVariant, ProductVariantId}; use rumqttc::QoS; use crate::AsyncClient; pub mod create_product_variant { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub product_id: ProductId, pub name: ProductVariantName, pub short_description: ProductShortDesc, pub long_description: ProductLongDesc, pub price: Price, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub product_variant: ProductVariant, } pub type Output = Result; } pub mod update_product_variant { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub id: ProductVariantId, pub product_id: ProductId, pub name: ProductVariantName, pub short_description: ProductShortDesc, pub long_description: ProductLongDesc, pub price: Price, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub product_variant: ProductVariant, } pub type Output = Result; } pub mod delete_product_variant { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub product_id: ProductId, pub product_variant_id: ProductVariantId, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub product_id: ProductId, pub product_variant_id: ProductVariantId, } pub type Output = Result; } pub enum Topic { ProductVariantCreated, ProductVariantUpdated, ProductVariantDeleted, } impl Topic { pub fn to_str(&self) -> &str { match self { Topic::ProductVariantCreated => "product-variant/created", Topic::ProductVariantUpdated => "product-variant/updated", Topic::ProductVariantDeleted => "product-variant/deleted", } } } impl Into for Topic { fn into(self) -> String { self.to_str().into() } } impl AsyncClient { pub async fn emit_product_variant_created(&self, product: &ProductVariant) { self.publish_or_log( Topic::ProductVariantCreated, QoS::AtLeastOnce, true, product, ) .await } pub async fn emit_product_variant_updated(&self, product: &ProductVariant) { self.publish_or_log( Topic::ProductVariantUpdated, QoS::AtLeastOnce, true, product, ) .await } pub async fn emit_product_variant_deleted(&self, product: &ProductVariantId) { self.publish_or_log( Topic::ProductVariantDeleted, QoS::AtLeastOnce, true, product, ) .await } }