refactor(transactions): improve code formatting and error handling in transaction service methods
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
use crate::errors::CommandResult;
|
||||
use crate::services::transactions::types::inputs::{BulkCreateTransactionInput, BulkDeleteInput, CreateTransactionInput, TransactionFilter, UpdateTransactionInput};
|
||||
use crate::services::transactions::types::outputs::{BulkDeleteResult, TransactionWithTags};
|
||||
use crate::services::transactions::types::inputs::TransactionStatistics;
|
||||
use crate::services::transactions::types::{
|
||||
inputs::{
|
||||
BulkCreateTransactionInput, BulkDeleteInput, CreateTransactionInput, TransactionFilter,
|
||||
TransactionStatistics, UpdateTransactionInput,
|
||||
},
|
||||
outputs::{BulkDeleteResult, TransactionWithTags},
|
||||
};
|
||||
use crate::state::AppState;
|
||||
|
||||
#[tauri::command]
|
||||
@@ -9,7 +13,10 @@ pub async fn create_transaction(
|
||||
state: tauri::State<'_, AppState>,
|
||||
input: CreateTransactionInput,
|
||||
) -> CommandResult<TransactionWithTags> {
|
||||
state.transaction_service().create_transaction(input, None).await
|
||||
state
|
||||
.transaction_service()
|
||||
.create_transaction(input, None)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -17,7 +24,10 @@ pub async fn get_transactions(
|
||||
state: tauri::State<'_, AppState>,
|
||||
filter: TransactionFilter,
|
||||
) -> CommandResult<Vec<TransactionWithTags>> {
|
||||
state.transaction_service().get_transactions(filter, None).await
|
||||
state
|
||||
.transaction_service()
|
||||
.get_transactions(filter, None)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -45,7 +55,10 @@ pub async fn delete_transaction(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
) -> CommandResult<()> {
|
||||
state.transaction_service().delete_transaction(id, None).await
|
||||
state
|
||||
.transaction_service()
|
||||
.delete_transaction(id, None)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -63,7 +76,10 @@ pub async fn confirm_transaction(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
) -> CommandResult<()> {
|
||||
state.transaction_service().confirm_transaction(id, None).await
|
||||
state
|
||||
.transaction_service()
|
||||
.confirm_transaction(id, None)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -938,8 +938,10 @@ impl TransactionService for TransactionServiceImpl {
|
||||
let updated = active_model.update(txn).await?;
|
||||
|
||||
// Determine if amount changed before we move updates
|
||||
let amount_changed =
|
||||
updates.net_amount.is_some() && updates.net_amount.as_ref().unwrap() != &old_amount;
|
||||
let amount_changed = updates.net_amount.is_some()
|
||||
&& updates.net_amount.as_ref().ok_or(AppError::InvalidData(
|
||||
"net_amount is required for amount change check".to_string(),
|
||||
))? != &old_amount;
|
||||
|
||||
// Get final tag list
|
||||
let tag_ids = if let Some(new_tags) = updates.tag_ids {
|
||||
@@ -1474,7 +1476,7 @@ mod tests {
|
||||
|
||||
// Should succeed even if transaction not found (counts as already deleted)
|
||||
assert!(result.is_ok(), "bulk_delete failed: {:?}", result);
|
||||
let delete_result = result.unwrap();
|
||||
let delete_result = result.expect("Failed to get bulk delete result");
|
||||
// When transaction not found, it's counted as success (already deleted)
|
||||
assert_eq!(delete_result.deleted_count, 1);
|
||||
assert!(delete_result.failed_ids.is_empty());
|
||||
|
||||
Reference in New Issue
Block a user