use rumqttc::QoS; use crate::AsyncClient; impl AsyncClient { pub async fn emit_category_created(&self, category: &model::v2::Category) { self.publish_or_log(Topic::CategoryCreated, QoS::AtLeastOnce, true, category) .await } pub async fn emit_category_updated(&self, category: &model::v2::Category) { self.publish_or_log(Topic::CategoryUpdated, QoS::AtLeastOnce, true, category) .await } pub async fn emit_category_deleted(&self, category_id: &model::v2::CategoryId) { self.publish_or_log(Topic::CategoryDeleted, QoS::AtLeastOnce, true, category_id) .await } } #[derive(Copy, Clone, Debug, PartialOrd, PartialEq, serde::Serialize, serde::Deserialize)] pub enum Topic { CategoryCreated, CategoryUpdated, CategoryDeleted, } impl Topic { pub fn to_str(self) -> &'static str { match self { Topic::CategoryCreated => "category/created", Topic::CategoryUpdated => "category/updated", Topic::CategoryDeleted => "category/deleted", } } } impl Into for Topic { fn into(self) -> String { self.to_str().into() } } impl<'s> PartialEq<&'s str> for Topic { fn eq(&self, other: &&'s str) -> bool { self.to_str() == *other } } impl PartialEq for Topic { fn eq(&self, other: &String) -> bool { self.to_str() == other.as_str() } } pub mod create_category { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub parent_id: Option, pub name: CategoryName, pub key: CategoryKey, pub svg: CategorySvg, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub product: Category, } pub type Output = Result; } pub mod delete_category { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub category_id: CategoryId, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub category: Option, } pub type Output = Result; } pub mod update_category { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub id: CategoryId, pub parent_id: Option, pub name: CategoryName, pub key: CategoryKey, pub svg: CategorySvg, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub category: Category, } pub type Output = Result; } pub mod all_categories { use model::v2::*; use crate::stocks::Error; #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Input { pub limit: Limit, pub offset: Offset, } #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Details { pub categories: Vec, } pub type Output = Result; }