bazzar/crates/channels/src/stocks/product_variant.rs

124 lines
2.9 KiB
Rust
Raw Normal View History

2022-11-18 16:31:52 +01:00
use model::v2::{ProductVariant, ProductVariantId};
use rumqttc::QoS;
use crate::AsyncClient;
2022-11-07 16:28:51 +01:00
pub mod create_product_variant {
use model::v2::*;
2022-11-08 07:49:06 +01:00
use crate::stocks::Error;
2022-11-07 16:28:51 +01:00
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Input {
pub product_id: ProductId,
2022-11-15 20:53:02 +01:00
pub name: ProductVariantName,
2022-11-07 16:28:51 +01:00
pub short_description: ProductShortDesc,
pub long_description: ProductLongDesc,
pub price: Price,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
2022-11-08 07:49:06 +01:00
pub struct Details {
2022-11-07 16:28:51 +01:00
pub product_variant: ProductVariant,
}
2022-11-08 07:49:06 +01:00
pub type Output = Result<Details, Error>;
2022-11-07 16:28:51 +01:00
}
pub mod update_product_variant {
use model::v2::*;
2022-11-08 07:49:06 +01:00
use crate::stocks::Error;
2022-11-07 16:28:51 +01:00
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Input {
pub id: ProductVariantId,
pub product_id: ProductId,
2022-11-18 16:31:52 +01:00
pub name: ProductVariantName,
2022-11-07 16:28:51 +01:00
pub short_description: ProductShortDesc,
pub long_description: ProductLongDesc,
pub price: Price,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
2022-11-08 07:49:06 +01:00
pub struct Details {
2022-11-07 16:28:51 +01:00
pub product_variant: ProductVariant,
}
2022-11-08 07:49:06 +01:00
pub type Output = Result<Details, Error>;
2022-11-07 16:28:51 +01:00
}
pub mod delete_product_variant {
use model::v2::*;
2022-11-08 07:49:06 +01:00
use crate::stocks::Error;
2022-11-07 16:28:51 +01:00
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Input {
pub product_id: ProductId,
pub product_variant_id: ProductVariantId,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
2022-11-08 07:49:06 +01:00
pub struct Details {
2022-11-07 16:28:51 +01:00
pub product_id: ProductId,
pub product_variant_id: ProductVariantId,
}
2022-11-08 07:49:06 +01:00
pub type Output = Result<Details, Error>;
2022-11-07 16:28:51 +01:00
}
2022-11-18 16:31:52 +01:00
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<String> 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
}
}