Skip to content

Commit

Permalink
refactor: split ChartPath enum into structs
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 13, 2025
1 parent 35505aa commit 0688e3d
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 468 deletions.
202 changes: 87 additions & 115 deletions core/chart-of-accounts/src/chart_of_accounts/entity.rs

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions core/chart-of-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use authz::PermissionCheck;

use chart_of_accounts::*;
use error::*;
use path::ControlAccountPath;
pub use path::ControlSubAccountPath;
pub use primitives::*;
pub use transaction_account_factory::*;

Expand Down Expand Up @@ -63,7 +65,7 @@ where
pub fn transaction_account_factory(
&self,
chart_id: ChartId,
control_sub_account: ChartPath,
control_sub_account: ControlSubAccountPath,
) -> TransactionAccountFactory {
TransactionAccountFactory::new(&self.repo, &self.cala, chart_id, control_sub_account)
}
Expand Down Expand Up @@ -152,7 +154,7 @@ where
&self,
chart_id: impl Into<ChartId>,
reference: String,
) -> Result<Option<ChartPath>, CoreChartOfAccountsError> {
) -> Result<Option<ControlAccountPath>, CoreChartOfAccountsError> {
let chart_id = chart_id.into();

let mut op = self.repo.begin_op().await?;
Expand All @@ -177,7 +179,7 @@ where
category: ChartCategory,
name: String,
reference: String,
) -> Result<ChartPath, CoreChartOfAccountsError> {
) -> Result<ControlAccountPath, CoreChartOfAccountsError> {
let chart_id = chart_id.into();

let mut op = self.repo.begin_op().await?;
Expand All @@ -194,20 +196,20 @@ where

let mut chart = self.repo.find_by_id(chart_id).await?;

let code = chart.create_control_account(category, name, reference, audit_info)?;
let path = chart.create_control_account(category, name, reference, audit_info)?;

self.repo.update_in_op(&mut op, &mut chart).await?;

op.commit().await?;

Ok(code)
Ok(path)
}

pub async fn find_control_sub_account_by_reference(
&self,
chart_id: impl Into<ChartId>,
reference: String,
) -> Result<Option<ChartPath>, CoreChartOfAccountsError> {
) -> Result<Option<ControlSubAccountPath>, CoreChartOfAccountsError> {
let chart_id = chart_id.into();

let mut op = self.repo.begin_op().await?;
Expand All @@ -229,10 +231,10 @@ where
pub async fn create_control_sub_account(
&self,
chart_id: impl Into<ChartId> + std::fmt::Debug,
control_account: ChartPath,
control_account: ControlAccountPath,
name: String,
reference: String,
) -> Result<ChartPath, CoreChartOfAccountsError> {
) -> Result<ControlSubAccountPath, CoreChartOfAccountsError> {
let chart_id = chart_id.into();

let mut op = self.repo.begin_op().await?;
Expand All @@ -249,15 +251,15 @@ where

let mut chart = self.repo.find_by_id(chart_id).await?;

let code =
let path =
chart.create_control_sub_account(control_account, name, reference, audit_info)?;

let mut op = self.repo.begin_op().await?;
self.repo.update_in_op(&mut op, &mut chart).await?;

op.commit().await?;

Ok(code)
Ok(path)
}

#[instrument(name = "chart_of_accounts.find_account_in_chart", skip(self))]
Expand Down
Loading

0 comments on commit 0688e3d

Please sign in to comment.