feat: utils to init cqrs framework

This commit is contained in:
Aravinth Manivannan 2025-01-10 20:11:17 +05:30
parent 501c6a4968
commit afda7a6ec8
Signed by: realaravinth
GPG key ID: F8F50389936984FF
10 changed files with 128 additions and 10 deletions

View file

@ -47,7 +47,9 @@ impl AddProductToStoreFTSPort for InventoryFTSMeili {
product: &Product, product: &Product,
category: &Category, category: &Category,
) -> InventoryFTSResult<()> { ) -> InventoryFTSResult<()> {
let store_index = self.client.index(format!("inventory-{}",category.store_id())); let store_index = self
.client
.index(format!("inventory-{}", category.store_id()));
let meili_product = MeiliProduct::new(product, category); let meili_product = MeiliProduct::new(product, category);
store_index store_index
.add_documents(&[meili_product], Some("product_id")) .add_documents(&[meili_product], Some("product_id"))

View file

@ -10,6 +10,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingCategoryCqrsExec, OrderingCategoryCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::category_aggregate::*; use crate::ordering::domain::category_aggregate::*;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::utils::parse_aggregate_id::parse_aggregate_id; use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -222,6 +224,20 @@ impl Query<Category> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingCategoryCqrsExec, OrderingCategoryCqrsView) {
let queries: Vec<Box<dyn Query<Category>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -12,13 +12,17 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{
OrderingCustomizationCqrsExec, OrderingCustomizationCqrsView,
};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::{customization_aggregate::*, events::OrderingEvent}; use crate::ordering::domain::{customization_aggregate::*, events::OrderingEvent};
use crate::utils::parse_aggregate_id::parse_aggregate_id; use crate::utils::parse_aggregate_id::parse_aggregate_id;
pub const NEW_CUSTOMIZATION_NON_UUID: &str = "ordering_new_customization_non_uuid-asdfa"; pub const NEW_CUSTOMIZATION_NON_UUID: &str = "ordering_new_customization_non_uuid-asdfa";
#[derive(Debug, Default, Serialize, Deserialize)] #[derive(Debug, Default, Serialize, Deserialize)]
struct CustomizationView { pub struct CustomizationView {
name: String, name: String,
product_id: Uuid, product_id: Uuid,
customization_id: Uuid, customization_id: Uuid,
@ -219,6 +223,20 @@ impl Query<Customization> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingCustomizationCqrsExec, OrderingCustomizationCqrsView) {
let queries: Vec<Box<dyn Query<Customization>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -13,6 +13,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingKotCqrsExec, OrderingKotCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::ordering::domain::kot_aggregate::*; use crate::ordering::domain::kot_aggregate::*;
use crate::types::quantity::*; use crate::types::quantity::*;
@ -229,6 +231,20 @@ impl Query<Kot> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingKotCqrsExec, OrderingKotCqrsView) {
let queries: Vec<Box<dyn Query<Kot>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -13,6 +13,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingLineItemCqrsExec, OrderingLineItemCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::ordering::domain::line_item_aggregate::*; use crate::ordering::domain::line_item_aggregate::*;
use crate::types::quantity::*; use crate::types::quantity::*;
@ -319,6 +321,20 @@ impl Query<LineItem> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingLineItemCqrsExec, OrderingLineItemCqrsView) {
let queries: Vec<Box<dyn Query<LineItem>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -10,24 +10,24 @@ use crate::db::{migrate::RunMigrations, sqlx_postgres::Postgres};
mod category_id_exists; mod category_id_exists;
mod category_name_exists_for_store; mod category_name_exists_for_store;
mod category_view; pub mod category_view;
mod customization_id_exists; mod customization_id_exists;
mod customization_name_exists_for_product; mod customization_name_exists_for_product;
mod customization_view; pub mod customization_view;
mod errors; mod errors;
mod get_category; mod get_category;
mod kot_id_exists; mod kot_id_exists;
mod kot_view; pub mod kot_view;
mod line_item_id_exists; mod line_item_id_exists;
mod line_item_view; pub mod line_item_view;
mod order_id_exists; mod order_id_exists;
mod order_view; pub mod order_view;
mod product_id_exists; mod product_id_exists;
mod product_name_exists_for_category; mod product_name_exists_for_category;
mod product_view; pub mod product_view;
mod store_id_exists; mod store_id_exists;
mod store_name_exists; mod store_name_exists;
mod store_view; pub mod store_view;
#[derive(Clone)] #[derive(Clone)]
pub struct OrderingDBPostgresAdapter { pub struct OrderingDBPostgresAdapter {

View file

@ -13,6 +13,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingOrderCqrsExec, OrderingOrderCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::ordering::domain::order_aggregate::*; use crate::ordering::domain::order_aggregate::*;
use crate::utils::parse_aggregate_id::parse_aggregate_id; use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -237,6 +239,20 @@ impl Query<Order> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingOrderCqrsExec, OrderingOrderCqrsView) {
let queries: Vec<Box<dyn Query<Order>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -12,6 +12,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingProductCqrsExec, OrderingProductCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::ordering::domain::product_aggregate::{Product, ProductBuilder}; use crate::ordering::domain::product_aggregate::{Product, ProductBuilder};
use crate::types::currency::*; use crate::types::currency::*;
@ -348,6 +350,20 @@ impl Query<Product> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingProductCqrsExec, OrderingProductCqrsView) {
let queries: Vec<Box<dyn Query<Product>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -10,6 +10,8 @@ use uuid::Uuid;
use super::errors::*; use super::errors::*;
use super::OrderingDBPostgresAdapter; use super::OrderingDBPostgresAdapter;
use crate::ordering::adapters::types::{OrderingStoreCqrsExec, OrderingStoreCqrsView};
use crate::ordering::application::services::OrderingServicesObj;
use crate::ordering::domain::events::OrderingEvent; use crate::ordering::domain::events::OrderingEvent;
use crate::ordering::domain::store_aggregate::*; use crate::ordering::domain::store_aggregate::*;
use crate::utils::parse_aggregate_id::parse_aggregate_id; use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -216,6 +218,20 @@ impl Query<Store> for OrderingDBPostgresAdapter {
} }
} }
pub fn init_cqrs(
db: OrderingDBPostgresAdapter,
services: OrderingServicesObj,
) -> (OrderingStoreCqrsExec, OrderingStoreCqrsView) {
let queries: Vec<Box<dyn Query<Store>>> = vec![Box::new(db.clone())];
let pool = db.pool.clone();
(
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
std::sync::Arc::new(db.clone()),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -47,7 +47,9 @@ impl AddProductToStoreFTSPort for OrderingFTSMeili {
product: &Product, product: &Product,
category: &Category, category: &Category,
) -> OrderingFTSResult<()> { ) -> OrderingFTSResult<()> {
let store_index = self.client.index(format!("ordering-{}",category.store_id())); let store_index = self
.client
.index(format!("ordering-{}", category.store_id()));
let meili_product = MeiliProduct::new(product, category); let meili_product = MeiliProduct::new(product, category);
store_index store_index
.add_documents(&[meili_product], Some("product_id")) .add_documents(&[meili_product], Some("product_id"))