-
Notifications
You must be signed in to change notification settings - Fork 0
api: migrate Transaction model/service to Decimal #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: migrate Transaction model/service to Decimal #94
Conversation
…QLx cache verified
Summary of ChangesHello @zensgit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request migrates the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the Transaction model and TransactionService from using f64 to rust_decimal::Decimal for monetary amounts. This change improves financial calculation precision by avoiding floating-point arithmetic issues common with monetary values.
- Transaction model amount fields changed from f64 to Decimal
- TransactionService balance queries updated to use Decimal type
- Added rust_decimal::Decimal import to both files
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| jive-api/src/models/transaction.rs | Updated Transaction, TransactionCreate, and TransactionUpdate structs to use Decimal for amount fields |
| jive-api/src/services/transaction_service.rs | Updated balance queries and HashMap type annotations to use Decimal instead of f64 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is a valuable change to migrate monetary values from f64 to Decimal, which is essential for financial accuracy. The modifications to the Transaction model are correct. However, the migration is incomplete in TransactionService, where some functions and structs still use f64. I've added a comment on the new Decimal import to highlight these areas that need to be updated to ensure consistency and prevent potential bugs. Completing this migration will solidify the correctness of the financial calculations.
| use crate::error::{ApiError, ApiResult}; | ||
| use crate::models::transaction::{Transaction, TransactionCreate, TransactionType}; | ||
| use chrono::{DateTime, Utc}; | ||
| use rust_decimal::Decimal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While Decimal has been correctly introduced for many parts of the service, the migration is incomplete in this file. There are still functions using f64 for monetary values, which could lead to precision errors and runtime bugs.
To complete the migration, please update the following:
-
auto_categorizefunction: The transactionamountis still fetched as anf64around line 284. This should beDecimal.// Around line 284 let transaction: Option<(String, Option<String>, f64)> = sqlx::query_as(...)
This should be changed to:
let transaction: Option<(String, Option<String>, Decimal)> = sqlx::query_as(...)
-
TransactionStatisticsstruct: This struct (around line 383) and its usage inget_statisticsstill rely onf64. All monetary fields should beDecimal.// Around line 383 pub struct TransactionStatistics { pub total_income: Option<f64>, pub total_expense: Option<f64>, pub net_amount: Option<f64>, pub avg_expense: Option<f64>, pub max_expense: Option<f64>, // ... }
This should be updated to use
Option<Decimal>for all monetary fields.
Ensuring Decimal is used consistently is critical for the correctness of financial calculations.
* api: move Transaction model and service to Decimal amounts; refresh SQLx cache verified * tests: add transaction amount serialization contract (Decimal as string)
Scope: Transaction model amount fields and TransactionService balances to Decimal. Validation: SQLx prepare, Clippy strict, tests all pass locally. No DB schema change (transactions.amount is DECIMAL).