diff options
author | rtkay123 <dev@kanjala.com> | 2025-08-09 10:36:07 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-08-09 10:36:07 +0200 |
commit | affa986bf1f84b725bd23309986250ff04cf2c93 (patch) | |
tree | 00faafcbdf1962793793e7581984078ce3466085 /crates | |
parent | 0f663ccb94581264e839bab9ae386114e8bd9973 (diff) | |
download | warden-affa986bf1f84b725bd23309986250ff04cf2c93.tar.bz2 warden-affa986bf1f84b725bd23309986250ff04cf2c93.zip |
feat: data cache
Diffstat (limited to 'crates')
-rw-r--r-- | crates/warden/Cargo.toml | 5 | ||||
-rw-r--r-- | crates/warden/src/server/routes/processor/pacs008.rs | 113 |
2 files changed, 115 insertions, 3 deletions
diff --git a/crates/warden/Cargo.toml b/crates/warden/Cargo.toml index 20c646b..231ccae 100644 --- a/crates/warden/Cargo.toml +++ b/crates/warden/Cargo.toml @@ -14,6 +14,7 @@ clap = { workspace = true, features = ["derive"] } config = { workspace = true, features = ["convert-case", "toml"] } serde = { workspace = true, features = ["derive"] } serde_json.workspace = true +time.workspace = true tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] } tracing.workspace = true utoipa = { workspace = true, features = ["axum_extras"] } @@ -22,10 +23,10 @@ utoipa-rapidoc = { workspace = true, optional = true } utoipa-redoc = { workspace = true, optional = true } utoipa-scalar = { workspace = true, optional = true } utoipa-swagger-ui = { workspace = true, optional = true } -warden-core = { workspace = true, features = ["iso20022", "openapi"] } +warden-core = { workspace = true, features = ["iso20022", "serde", "openapi"] } [features] -# default = [] +default = [] swagger = ["dep:utoipa-swagger-ui", "utoipa-swagger-ui/axum"] redoc = ["dep:utoipa-redoc", "utoipa-redoc/axum"] rapidoc = ["dep:utoipa-rapidoc", "utoipa-rapidoc/axum"] diff --git a/crates/warden/src/server/routes/processor/pacs008.rs b/crates/warden/src/server/routes/processor/pacs008.rs index cde5c07..66df598 100644 --- a/crates/warden/src/server/routes/processor/pacs008.rs +++ b/crates/warden/src/server/routes/processor/pacs008.rs @@ -1,5 +1,9 @@ use axum::{extract::State, response::IntoResponse}; -use warden_core::iso20022::pacs008::Pacs008Document; +use tracing::trace; +use warden_core::{ + iso20022::{TransactionType, pacs008::Pacs008Document}, + message::DataCache, +}; use crate::{error::AppError, server::routes::PACS008_001_12, state::AppHandle, version::Version}; @@ -31,5 +35,112 @@ pub(super) async fn post_pacs008( State(state): State<AppHandle>, axum::Json(transaction): axum::Json<Pacs008Document>, ) -> Result<impl IntoResponse, AppError> { + let tx_tp = TransactionType::PACS008; Ok(String::default()) } + +pub fn build_data_cache(transaction: &Pacs008Document) -> anyhow::Result<DataCache> { + trace!("building data cache object"); + let cdt_trf_tx_inf = transaction.f_i_to_f_i_cstmr_cdt_trf.cdt_trf_tx_inf.first(); + + let instd_amt = cdt_trf_tx_inf.and_then(|value| value.instd_amt.clone()); + + let intr_bk_sttlm_amt = cdt_trf_tx_inf.and_then(|value| value.intr_bk_sttlm_amt.clone()); + + let xchg_rate = cdt_trf_tx_inf.and_then(|value| value.xchg_rate); + let cre_dt_tm = transaction.f_i_to_f_i_cstmr_cdt_trf.grp_hdr.cre_dt_tm; + + let dbtr_othr = cdt_trf_tx_inf.and_then(|value| { + value + .dbtr + .id + .as_ref() + .and_then(|value| value.prvt_id.othr.first()) + }); + + let debtor_id = dbtr_othr + .and_then(|value| { + value + .schme_nm + .as_ref() + .map(|schme_nm| format!("{}{}", value.id, schme_nm.prtry)) + }) + .ok_or_else(|| anyhow::anyhow!("missing debtor id"))?; + + let cdtr_othr = cdt_trf_tx_inf.and_then(|value| { + value.cdtr.as_ref().and_then(|value| { + value + .id + .as_ref() + .and_then(|value| value.prvt_id.othr.first()) + }) + }); + + let creditor_id = cdtr_othr + .and_then(|value| { + value + .schme_nm + .as_ref() + .map(|schme_nm| format!("{}{}", value.id, schme_nm.prtry)) + }) + .ok_or_else(|| anyhow::anyhow!("missing creditor id"))?; + + let dbtr_acct_othr = cdt_trf_tx_inf.and_then(|value| { + value + .dbtr_acct + .as_ref() + .and_then(|value| value.id.as_ref().map(|value| value.othr.clone())) + }); + let dbtr_mmb_id = cdt_trf_tx_inf.and_then(|value| { + value.dbtr_agt.as_ref().and_then(|value| { + value + .fin_instn_id + .clr_sys_mmb_id + .as_ref() + .map(|value| value.mmb_id.as_str()) + }) + }); + + let debtor_acct_id = if let (Some(a), Some(b)) = (dbtr_acct_othr, dbtr_mmb_id) { + Some(format!("{}{b}", a.id)) + } else { + None + } + .ok_or_else(|| anyhow::anyhow!("missing debtor_acct_id"))?; + + let cdtr_acct_othr = cdt_trf_tx_inf.and_then(|value| { + value + .cdtr_acct + .as_ref() + .and_then(|value| value.id.as_ref().map(|value| value.othr.clone())) + }); + let cdtr_mmb_id = cdt_trf_tx_inf.and_then(|value| { + value.cdtr_agt.as_ref().and_then(|value| { + value + .fin_instn_id + .clr_sys_mmb_id + .as_ref() + .map(|value| value.mmb_id.as_str()) + }) + }); + + let creditor_acct_id = if let (Some(a), Some(b)) = (cdtr_acct_othr, cdtr_mmb_id) { + Some(format!("{}{b}", a.id)) + } else { + None + } + .ok_or_else(|| anyhow::anyhow!("missing creditor_acct_id"))?; + + let data_cache = DataCache { + cdtr_id: creditor_id.to_string(), + dbtr_id: debtor_id.to_string(), + dbtr_acct_id: debtor_acct_id.to_string(), + cdtr_acct_id: creditor_acct_id.to_string(), + cre_dt_tm: Some(cre_dt_tm), + instd_amt, + intr_bk_sttlm_amt, + xchg_rate, + }; + + Ok(data_cache) +} |