feat: inventory: init cqrs framework for aggregates

This commit is contained in:
Aravinth Manivannan 2025-01-10 18:56:23 +05:30
parent c296451401
commit 5dcae64a04
Signed by: realaravinth
GPG key ID: F8F50389936984FF
5 changed files with 74 additions and 5 deletions

View file

@ -10,6 +10,8 @@ use uuid::Uuid;
use super::errors::*;
use super::InventoryDBPostgresAdapter;
use crate::inventory::adapters::types::{InventoryCategoryCqrsExec, InventoryCategoryCqrsView};
use crate::inventory::application::services::InventoryServicesObj;
use crate::inventory::domain::category_aggregate::{Category, CategoryBuilder};
use crate::inventory::domain::events::InventoryEvent;
use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -229,6 +231,20 @@ impl Query<Category> for InventoryDBPostgresAdapter {
}
}
pub fn init_cqrs(
db: InventoryDBPostgresAdapter,
services: InventoryServicesObj,
) -> (InventoryCategoryCqrsExec, InventoryCategoryCqrsView) {
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::*;

View file

@ -12,6 +12,10 @@ use uuid::Uuid;
use super::errors::*;
use super::InventoryDBPostgresAdapter;
use crate::inventory::adapters::types::{
InventoryCustomizationCqrsExec, InventoryCustomizationCqrsView,
};
use crate::inventory::application::services::InventoryServicesObj;
use crate::inventory::domain::{customization_aggregate::*, events::InventoryEvent};
use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -23,7 +27,7 @@ pub const NEW_CUSTOMIZATION_NON_UUID: &str = "new_customization_non_uuid-asdfa";
//}
#[derive(Debug, Default, Serialize, Deserialize)]
struct CustomizationView {
pub struct CustomizationView {
name: String,
product_id: Uuid,
customization_id: Uuid,
@ -224,6 +228,23 @@ impl Query<Customization> for InventoryDBPostgresAdapter {
}
}
pub fn init_cqrs(
db: InventoryDBPostgresAdapter,
services: InventoryServicesObj,
) -> (
InventoryCustomizationCqrsExec,
InventoryCustomizationCqrsView,
) {
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::*;

View file

@ -10,18 +10,18 @@ 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 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 InventoryDBPostgresAdapter {

View file

@ -12,6 +12,8 @@ use uuid::Uuid;
use super::errors::*;
use super::InventoryDBPostgresAdapter;
use crate::inventory::adapters::types::{InventoryProductCqrsExec, InventoryProductCqrsView};
use crate::inventory::application::services::InventoryServicesObj;
use crate::inventory::domain::events::InventoryEvent;
use crate::inventory::domain::product_aggregate::{Product, ProductBuilder};
use crate::types::currency::*;
@ -348,6 +350,20 @@ impl Query<Product> for InventoryDBPostgresAdapter {
}
}
pub fn init_cqrs(
db: InventoryDBPostgresAdapter,
services: InventoryServicesObj,
) -> (InventoryProductCqrsExec, InventoryProductCqrsView) {
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::*;

View file

@ -10,6 +10,8 @@ use uuid::Uuid;
use super::errors::*;
use super::InventoryDBPostgresAdapter;
use crate::inventory::adapters::types::{InventoryStoreCqrsExec, InventoryStoreCqrsView};
use crate::inventory::application::services::InventoryServicesObj;
use crate::inventory::domain::events::InventoryEvent;
use crate::inventory::domain::store_aggregate::{Store, StoreBuilder};
use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -225,6 +227,20 @@ impl Query<Store> for InventoryDBPostgresAdapter {
}
}
pub fn init_cqrs(
db: InventoryDBPostgresAdapter,
services: InventoryServicesObj,
) -> (InventoryStoreCqrsExec, InventoryStoreCqrsView) {
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::*;