fix: rename bililng cqrs types, and use struct to aggregate all execs
This commit is contained in:
parent
3e884cac06
commit
ae9cbe953d
3 changed files with 47 additions and 21 deletions
|
@ -61,10 +61,10 @@ const UUID: Uuid = uuid::uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8");
|
|||
#[post("/billing/store/add")]
|
||||
#[tracing::instrument(
|
||||
name = "add store handler",
|
||||
skip(billing_store_cqrs_exec, billing_store_cqrs_view, uuid_generator)
|
||||
skip(billing_cqrs_exec, billing_store_cqrs_view, uuid_generator)
|
||||
)]
|
||||
async fn add_store_submit_handler(
|
||||
billing_store_cqrs_exec: types::WebBillingStoreCqrsExec,
|
||||
billing_cqrs_exec: types::WebBillingCqrsExec,
|
||||
billing_store_cqrs_view: types::WebBillingStoreCqrsView,
|
||||
uuid_generator: WebGetUUIDInterfaceObj,
|
||||
req: HttpRequest,
|
||||
|
@ -83,7 +83,7 @@ async fn add_store_submit_handler(
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
billing_store_cqrs_exec
|
||||
billing_cqrs_exec
|
||||
.execute(&store_uuid_str, BillingCommand::AddStore(cmd))
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -132,10 +132,10 @@ async fn add_bill_page_handler() -> WebJsonRepsonse<impl Responder> {
|
|||
#[post("/billing/bill/add")]
|
||||
#[tracing::instrument(
|
||||
name = "add bill handler",
|
||||
skip(billing_bill_cqrs_exec, billing_bill_cqrs_view,)
|
||||
skip(billing_cqrs_exec, billing_bill_cqrs_view,)
|
||||
)]
|
||||
async fn add_bill_submit_handler(
|
||||
billing_bill_cqrs_exec: types::WebBillingBillCqrsExec,
|
||||
billing_cqrs_exec: types::WebBillingCqrsExec,
|
||||
billing_bill_cqrs_view: types::WebBillingBillCqrsView,
|
||||
req: HttpRequest,
|
||||
// id: Identity,
|
||||
|
@ -153,7 +153,7 @@ async fn add_bill_submit_handler(
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
billing_bill_cqrs_exec
|
||||
billing_cqrs_exec
|
||||
.execute(&bill_uuid_str, BillingCommand::AddBill(cmd))
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
|
@ -53,17 +53,21 @@ pub fn load_adapters(pool: PgPool, settings: Settings) -> impl FnOnce(&mut web::
|
|||
let (line_item_cqrs_exec, line_item_cqrs_query) =
|
||||
line_item_view::init_cqrs(db.clone(), services.clone());
|
||||
|
||||
let billing_cqrs_exec = types::BillingCqrsExecBuilder::default()
|
||||
.bill(bill_cqrs_exec)
|
||||
.line_item(line_item_cqrs_exec)
|
||||
.store(store_cqrs_exec)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let f = move |cfg: &mut web::ServiceConfig| {
|
||||
cfg.configure(input::web::load_ctx());
|
||||
|
||||
cfg.app_data(Data::new(bill_cqrs_exec.clone()));
|
||||
cfg.app_data(Data::new(bill_cqrs_query.clone()));
|
||||
|
||||
cfg.app_data(Data::new(store_cqrs_exec.clone()));
|
||||
cfg.app_data(Data::new(store_cqrs_query.clone()));
|
||||
|
||||
cfg.app_data(Data::new(line_item_cqrs_exec.clone()));
|
||||
cfg.app_data(Data::new(line_item_cqrs_query.clone()));
|
||||
|
||||
cfg.app_data(Data::new(Arc::new(billing_cqrs_exec)));
|
||||
};
|
||||
|
||||
Box::new(f)
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
@ -10,7 +6,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web::Data;
|
||||
use cqrs_es::persist::ViewRepository;
|
||||
use cqrs_es::{persist::ViewRepository, AggregateError};
|
||||
use derive_builder::Builder;
|
||||
use postgres_es::PostgresCqrs;
|
||||
|
||||
use crate::billing::{
|
||||
|
@ -21,8 +18,11 @@ use crate::billing::{
|
|||
BillingDBPostgresAdapter,
|
||||
},
|
||||
},
|
||||
application::services::BillingServicesObj,
|
||||
domain::{bill_aggregate::Bill, line_item_aggregate::LineItem, store_aggregate::Store},
|
||||
application::services::{errors::BillingError, BillingServicesObj},
|
||||
domain::{
|
||||
bill_aggregate::Bill, commands::BillingCommand, line_item_aggregate::LineItem,
|
||||
store_aggregate::Store,
|
||||
},
|
||||
};
|
||||
|
||||
pub type WebBillingRoutesRepository = Data<Arc<RoutesRepository>>;
|
||||
|
@ -30,16 +30,38 @@ pub type WebBillingRoutesRepository = Data<Arc<RoutesRepository>>;
|
|||
pub type WebBillingServiceObj = Data<BillingServicesObj>;
|
||||
|
||||
pub type BillingBillCqrsExec = Arc<PostgresCqrs<Bill>>;
|
||||
pub type WebBillingBillCqrsExec = Data<BillingBillCqrsExec>;
|
||||
pub type BillingBillCqrsView = Arc<dyn ViewRepository<BillView, Bill>>;
|
||||
pub type WebBillingBillCqrsView = Data<BillingBillCqrsView>;
|
||||
|
||||
pub type BillingLineItemCqrsExec = Arc<PostgresCqrs<LineItem>>;
|
||||
pub type WebBillingLineItemCqrsExec = Data<BillingLineItemCqrsExec>;
|
||||
pub type BillingLineItemCqrsView = Arc<dyn ViewRepository<LineItemView, LineItem>>;
|
||||
pub type WebBillingLineItemCqrsView = Data<BillingLineItemCqrsView>;
|
||||
|
||||
pub type BillingStoreCqrsExec = Arc<PostgresCqrs<Store>>;
|
||||
pub type WebBillingStoreCqrsExec = Data<BillingStoreCqrsExec>;
|
||||
pub type BillingStoreCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
||||
pub type WebBillingStoreCqrsView = Data<BillingStoreCqrsView>;
|
||||
|
||||
pub type WebBillingCqrsExec = Data<Arc<BillingCqrsExec>>;
|
||||
|
||||
#[derive(Clone, Builder)]
|
||||
pub struct BillingCqrsExec {
|
||||
bill: BillingBillCqrsExec,
|
||||
line_item: BillingLineItemCqrsExec,
|
||||
store: BillingStoreCqrsExec,
|
||||
}
|
||||
|
||||
impl BillingCqrsExec {
|
||||
pub async fn execute(
|
||||
&self,
|
||||
aggregate_id: &str,
|
||||
command: BillingCommand,
|
||||
) -> Result<(), AggregateError<BillingError>> {
|
||||
self.bill.execute(aggregate_id, command.clone()).await?;
|
||||
self.line_item
|
||||
.execute(aggregate_id, command.clone())
|
||||
.await?;
|
||||
self.store.execute(aggregate_id, command).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue