feat: load billing adapters #125

Merged
realaravinth merged 63 commits from load-billing-adapter into master 2025-01-11 19:41:14 +05:30
Showing only changes of commit 532c6410e1 - Show all commits

View 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(())
}
}