feat: ordering adapter type aliases
This commit is contained in:
parent
53da156897
commit
a17cc52633
1 changed files with 107 additions and 0 deletions
107
src/ordering/adapters/types.rs
Normal file
107
src/ordering/adapters/types.rs
Normal file
|
@ -0,0 +1,107 @@
|
|||
// 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::ordering::{
|
||||
adapters::{
|
||||
// input::web::RoutesRepository,
|
||||
output::db::{
|
||||
category_view::CategoryView, customization_view::CustomizationView, kot_view::KotView,
|
||||
line_item_view::LineItemView, order_view::OrderView, product_view::ProductView,
|
||||
store_view::StoreView, OrderingDBPostgresAdapter,
|
||||
},
|
||||
},
|
||||
application::services::{errors::OrderingError, OrderingServicesObj},
|
||||
domain::{
|
||||
category_aggregate::Category, commands::OrderingCommand,
|
||||
customization_aggregate::Customization, kot_aggregate::Kot, line_item_aggregate::LineItem,
|
||||
order_aggregate::Order, product_aggregate::Product, store_aggregate::Store,
|
||||
},
|
||||
};
|
||||
|
||||
//pub type WebOrderingRoutesRepository = Data<Arc<RoutesRepository>>;
|
||||
|
||||
pub type OrderingOrderCqrsExec = Arc<PostgresCqrs<Order>>;
|
||||
pub type OrderingOrderCqrsView = Arc<dyn ViewRepository<OrderView, Order>>;
|
||||
pub type WebOrderingOrderCqrsView = Data<OrderingOrderCqrsView>;
|
||||
|
||||
pub type OrderingCategoryCqrsExec = Arc<PostgresCqrs<Category>>;
|
||||
pub type OrderingCategoryCqrsView = Arc<dyn ViewRepository<CategoryView, Category>>;
|
||||
pub type WebOrderingCategoryCqrsView = Data<OrderingCategoryCqrsView>;
|
||||
|
||||
pub type OrderingKotCqrsExec = Arc<PostgresCqrs<Kot>>;
|
||||
pub type OrderingKotCqrsView = Arc<dyn ViewRepository<KotView, Kot>>;
|
||||
pub type WebOrderingKotCqrsView = Data<OrderingKotCqrsView>;
|
||||
|
||||
pub type OrderingStoreCqrsExec = Arc<PostgresCqrs<Store>>;
|
||||
pub type OrderingStoreCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
||||
pub type WebOrderingStoreCqrsView = Data<OrderingStoreCqrsView>;
|
||||
|
||||
pub type OrderingCustomizationCqrsExec = Arc<PostgresCqrs<Customization>>;
|
||||
pub type OrderingCustomizationCqrsView = Arc<dyn ViewRepository<CustomizationView, Customization>>;
|
||||
pub type WebOrderingCustomizationCqrsView = Data<OrderingCustomizationCqrsView>;
|
||||
|
||||
pub type OrderingProductCqrsExec = Arc<PostgresCqrs<Product>>;
|
||||
pub type OrderingProductCqrsView = Arc<dyn ViewRepository<ProductView, Product>>;
|
||||
pub type WebOrderingProductCqrsView = Data<OrderingProductCqrsView>;
|
||||
|
||||
pub type OrderingLineItemCqrsExec = Arc<PostgresCqrs<LineItem>>;
|
||||
pub type OrderingLineItemCqrsView = Arc<dyn ViewRepository<LineItemView, LineItem>>;
|
||||
pub type WebOrderingLineItemCqrsView = Data<OrderingLineItemCqrsView>;
|
||||
|
||||
pub type WebOrderingCqrsExec = Data<Arc<dyn OrderingCqrsExecutor>>;
|
||||
|
||||
#[automock]
|
||||
#[async_trait]
|
||||
pub trait OrderingCqrsExecutor {
|
||||
async fn execute(
|
||||
&self,
|
||||
aggregate_id: &str,
|
||||
command: OrderingCommand,
|
||||
) -> Result<(), AggregateError<OrderingError>>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Builder)]
|
||||
pub struct OrderingCqrsExec {
|
||||
store: OrderingStoreCqrsExec,
|
||||
product: OrderingProductCqrsExec,
|
||||
line_item: OrderingLineItemCqrsExec,
|
||||
customization: OrderingCustomizationCqrsExec,
|
||||
kot: OrderingKotCqrsExec,
|
||||
category: OrderingCategoryCqrsExec,
|
||||
order: OrderingOrderCqrsExec,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl OrderingCqrsExecutor for OrderingCqrsExec {
|
||||
async fn execute(
|
||||
&self,
|
||||
aggregate_id: &str,
|
||||
command: OrderingCommand,
|
||||
) -> Result<(), AggregateError<OrderingError>> {
|
||||
self.kot.execute(aggregate_id, command.clone()).await?;
|
||||
self.order.execute(aggregate_id, command.clone()).await?;
|
||||
self.line_item
|
||||
.execute(aggregate_id, command.clone())
|
||||
.await?;
|
||||
self.product.execute(aggregate_id, command.clone()).await?;
|
||||
self.store.execute(aggregate_id, command.clone()).await?;
|
||||
self.customization
|
||||
.execute(aggregate_id, command.clone())
|
||||
.await?;
|
||||
self.category.execute(aggregate_id, command).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue