Refactored src and dst account to just account in preparation for a "counter party", instead of a full account.
This commit is contained in:
@@ -68,7 +68,7 @@ async fn list_scheduled_transactions(
|
||||
let responses = transactions
|
||||
.into_iter()
|
||||
.map(|transaction| create_response(transaction, &accounts, now))
|
||||
.collect();
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(Json(responses))
|
||||
}
|
||||
@@ -87,7 +87,7 @@ async fn get_scheduled_transaction(
|
||||
get_accounts_for_transactions(&mut tx, std::slice::from_ref(&transaction)).await?;
|
||||
tx.commit().await.map_err(RepositoryError::from)?;
|
||||
|
||||
Ok(Json(create_response(transaction, &accounts, Utc::now())))
|
||||
Ok(Json(create_response(transaction, &accounts, Utc::now())?))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
@@ -111,7 +111,7 @@ async fn upsert_scheduled_transaction(
|
||||
|
||||
Ok((
|
||||
status,
|
||||
Json(create_response(transaction, &accounts, Utc::now())),
|
||||
Json(create_response(transaction, &accounts, Utc::now())?),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -133,13 +133,7 @@ async fn get_accounts_for_transactions(
|
||||
) -> Result<HashMap<Uuid, domain::Account>, AppError> {
|
||||
let account_ids = transactions
|
||||
.iter()
|
||||
.flat_map(|transaction| {
|
||||
[
|
||||
transaction.source_account_id,
|
||||
transaction.destination_account_id,
|
||||
]
|
||||
})
|
||||
.flatten()
|
||||
.map(|transaction| transaction.account_id)
|
||||
.collect::<HashSet<_>>()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
@@ -151,15 +145,13 @@ fn create_response(
|
||||
transaction: domain::RecurringTransaction,
|
||||
accounts: &HashMap<Uuid, domain::Account>,
|
||||
now: DateTime<Utc>,
|
||||
) -> ScheduledTransactionResponse {
|
||||
let source_account = transaction
|
||||
.source_account_id
|
||||
.and_then(|id| accounts.get(&id).cloned());
|
||||
let destination_account = transaction
|
||||
.destination_account_id
|
||||
.and_then(|id| accounts.get(&id).cloned());
|
||||
) -> Result<ScheduledTransactionResponse, AppError> {
|
||||
let account = accounts
|
||||
.get(&transaction.account_id)
|
||||
.cloned()
|
||||
.ok_or(AppError::Internal)?;
|
||||
|
||||
let next = transaction.schedule.next_occurrence(now);
|
||||
|
||||
RecurringTransactionResponse::new(transaction, source_account, destination_account, next).into()
|
||||
Ok(RecurringTransactionResponse::new(transaction, account, next).into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user