Skip to content

Conversation

zensgit
Copy link
Owner

@zensgit zensgit commented Oct 15, 2025

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).

@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 15:23
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 Transaction model and TransactionService to use the Decimal type for all amount-related fields and balance calculations. This change is crucial for maintaining accuracy in financial operations by avoiding the inherent precision issues of floating-point numbers, without requiring any database schema modifications.

Highlights

  • Data Type Migration: Changed amount fields in Transaction, TransactionCreate, and TransactionUpdate structs from f64 to rust_decimal::Decimal to prevent floating-point inaccuracies in financial calculations.
  • Service Logic Update: Updated TransactionService methods to use Decimal for handling account balances, ensuring consistent precision across the API.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@Copilot Copilot AI left a 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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:

  1. auto_categorize function: The transaction amount is still fetched as an f64 around line 284. This should be Decimal.

    // 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(...)
  2. TransactionStatistics struct: This struct (around line 383) and its usage in get_statistics still rely on f64. All monetary fields should be Decimal.

    // 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.

@zensgit zensgit merged commit 476e98b into chore/invitations-audit-align-dev-mock Oct 15, 2025
@zensgit zensgit deleted the chore/decimal-models-transaction-budget branch October 15, 2025 15:56
zensgit added a commit that referenced this pull request Oct 16, 2025
* api: move Transaction model and service to Decimal amounts; refresh SQLx cache verified

* tests: add transaction amount serialization contract (Decimal as string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant