diff --git a/src/ordering/adapters/types.rs b/src/ordering/adapters/types.rs new file mode 100644 index 0000000..5b1c66b --- /dev/null +++ b/src/ordering/adapters/types.rs @@ -0,0 +1,107 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// 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>; + +pub type OrderingOrderCqrsExec = Arc>; +pub type OrderingOrderCqrsView = Arc>; +pub type WebOrderingOrderCqrsView = Data; + +pub type OrderingCategoryCqrsExec = Arc>; +pub type OrderingCategoryCqrsView = Arc>; +pub type WebOrderingCategoryCqrsView = Data; + +pub type OrderingKotCqrsExec = Arc>; +pub type OrderingKotCqrsView = Arc>; +pub type WebOrderingKotCqrsView = Data; + +pub type OrderingStoreCqrsExec = Arc>; +pub type OrderingStoreCqrsView = Arc>; +pub type WebOrderingStoreCqrsView = Data; + +pub type OrderingCustomizationCqrsExec = Arc>; +pub type OrderingCustomizationCqrsView = Arc>; +pub type WebOrderingCustomizationCqrsView = Data; + +pub type OrderingProductCqrsExec = Arc>; +pub type OrderingProductCqrsView = Arc>; +pub type WebOrderingProductCqrsView = Data; + +pub type OrderingLineItemCqrsExec = Arc>; +pub type OrderingLineItemCqrsView = Arc>; +pub type WebOrderingLineItemCqrsView = Data; + +pub type WebOrderingCqrsExec = Data>; + +#[automock] +#[async_trait] +pub trait OrderingCqrsExecutor { + async fn execute( + &self, + aggregate_id: &str, + command: OrderingCommand, + ) -> Result<(), AggregateError>; +} + +#[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> { + 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(()) + } +}