feat: utils to init cqrs framework
This commit is contained in:
parent
501c6a4968
commit
afda7a6ec8
10 changed files with 128 additions and 10 deletions
|
@ -47,7 +47,9 @@ impl AddProductToStoreFTSPort for InventoryFTSMeili {
|
|||
product: &Product,
|
||||
category: &Category,
|
||||
) -> 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);
|
||||
store_index
|
||||
.add_documents(&[meili_product], Some("product_id"))
|
||||
|
|
|
@ -10,6 +10,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::events::OrderingEvent;
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -12,13 +12,17 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::utils::parse_aggregate_id::parse_aggregate_id;
|
||||
|
||||
pub const NEW_CUSTOMIZATION_NON_UUID: &str = "ordering_new_customization_non_uuid-asdfa";
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
struct CustomizationView {
|
||||
pub struct CustomizationView {
|
||||
name: String,
|
||||
product_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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -13,6 +13,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::kot_aggregate::*;
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -13,6 +13,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::line_item_aggregate::*;
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -10,24 +10,24 @@ use crate::db::{migrate::RunMigrations, sqlx_postgres::Postgres};
|
|||
|
||||
mod category_id_exists;
|
||||
mod category_name_exists_for_store;
|
||||
mod category_view;
|
||||
pub mod category_view;
|
||||
mod customization_id_exists;
|
||||
mod customization_name_exists_for_product;
|
||||
mod customization_view;
|
||||
pub mod customization_view;
|
||||
mod errors;
|
||||
mod get_category;
|
||||
mod kot_id_exists;
|
||||
mod kot_view;
|
||||
pub mod kot_view;
|
||||
mod line_item_id_exists;
|
||||
mod line_item_view;
|
||||
pub mod line_item_view;
|
||||
mod order_id_exists;
|
||||
mod order_view;
|
||||
pub mod order_view;
|
||||
mod product_id_exists;
|
||||
mod product_name_exists_for_category;
|
||||
mod product_view;
|
||||
pub mod product_view;
|
||||
mod store_id_exists;
|
||||
mod store_name_exists;
|
||||
mod store_view;
|
||||
pub mod store_view;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OrderingDBPostgresAdapter {
|
||||
|
|
|
@ -13,6 +13,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::order_aggregate::*;
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -12,6 +12,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::product_aggregate::{Product, ProductBuilder};
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -10,6 +10,8 @@ use uuid::Uuid;
|
|||
|
||||
use super::errors::*;
|
||||
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::store_aggregate::*;
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -47,7 +47,9 @@ impl AddProductToStoreFTSPort for OrderingFTSMeili {
|
|||
product: &Product,
|
||||
category: &Category,
|
||||
) -> 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);
|
||||
store_index
|
||||
.add_documents(&[meili_product], Some("product_id"))
|
||||
|
|
Loading…
Reference in a new issue