feat: define inventory adapter type aliases
This commit is contained in:
parent
4974f388d7
commit
532c6410e1
1 changed files with 85 additions and 0 deletions
85
src/inventory/adapters/types.rs
Normal file
85
src/inventory/adapters/types.rs
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use actix_web::web::Data;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use cqrs_es::{persist::ViewRepository, AggregateError};
|
||||||
|
use derive_builder::Builder;
|
||||||
|
use mockall::predicate::*;
|
||||||
|
use mockall::*;
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::inventory::{
|
||||||
|
adapters::{
|
||||||
|
// input::web::RoutesRepository,
|
||||||
|
output::db::postgres::{
|
||||||
|
category_view::CategoryView, customization_view::CustomizationView,
|
||||||
|
product_view::ProductView, store_view::StoreView, InventoryDBPostgresAdapter,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
application::services::{errors::InventoryError, InventoryServicesObj},
|
||||||
|
domain::{
|
||||||
|
category_aggregate::Category, commands::InventoryCommand,
|
||||||
|
customization_aggregate::Customization, product_aggregate::Product, store_aggregate::Store,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
//pub type WebInventoryRoutesRepository = Data<Arc<RoutesRepository>>;
|
||||||
|
|
||||||
|
pub type WebInventoryCqrsExec = Data<Arc<dyn InventoryCqrsExecutor>>;
|
||||||
|
|
||||||
|
pub type InventoryCustomizationCqrsExec = Arc<PostgresCqrs<Customization>>;
|
||||||
|
pub type InventoryCustomizationCqrsView = Arc<dyn ViewRepository<CustomizationView, Customization>>;
|
||||||
|
pub type WebInventoryCustomizationCqrsView = Data<InventoryCustomizationCqrsView>;
|
||||||
|
|
||||||
|
pub type InventoryCategoryCqrsExec = Arc<PostgresCqrs<Category>>;
|
||||||
|
pub type InventoryCategoryCqrsView = Arc<dyn ViewRepository<CategoryView, Category>>;
|
||||||
|
pub type WebInventoryCategoryCqrsView = Data<InventoryCategoryCqrsView>;
|
||||||
|
|
||||||
|
pub type InventoryStoreCqrsExec = Arc<PostgresCqrs<Store>>;
|
||||||
|
pub type InventoryStoreCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
||||||
|
pub type WebInventoryStoreCqrsView = Data<InventoryStoreCqrsView>;
|
||||||
|
|
||||||
|
pub type InventoryProductCqrsExec = Arc<PostgresCqrs<Product>>;
|
||||||
|
pub type InventoryProductCqrsView = Arc<dyn ViewRepository<ProductView, Product>>;
|
||||||
|
pub type WebInventoryProductCqrsView = Data<InventoryProductCqrsView>;
|
||||||
|
|
||||||
|
#[automock]
|
||||||
|
#[async_trait]
|
||||||
|
pub trait InventoryCqrsExecutor {
|
||||||
|
async fn execute(
|
||||||
|
&self,
|
||||||
|
aggregate_id: &str,
|
||||||
|
command: InventoryCommand,
|
||||||
|
) -> Result<(), AggregateError<InventoryError>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Builder)]
|
||||||
|
pub struct InventoryCqrsExec {
|
||||||
|
category: InventoryCategoryCqrsExec,
|
||||||
|
customization: InventoryCustomizationCqrsExec,
|
||||||
|
store: InventoryStoreCqrsExec,
|
||||||
|
product: InventoryProductCqrsExec,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl InventoryCqrsExecutor for InventoryCqrsExec {
|
||||||
|
async fn execute(
|
||||||
|
&self,
|
||||||
|
aggregate_id: &str,
|
||||||
|
command: InventoryCommand,
|
||||||
|
) -> Result<(), AggregateError<InventoryError>> {
|
||||||
|
self.category.execute(aggregate_id, command.clone()).await?;
|
||||||
|
self.customization
|
||||||
|
.execute(aggregate_id, command.clone())
|
||||||
|
.await?;
|
||||||
|
self.store.execute(aggregate_id, command.clone()).await?;
|
||||||
|
self.product.execute(aggregate_id, command.clone()).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue