Skip to content

refactor(usecases): ensure that every repository call happens within uow#23

Merged
madalinpopa merged 28 commits intomainfrom
branch/push-utqwyssyttom
Feb 10, 2026
Merged

refactor(usecases): ensure that every repository call happens within uow#23
madalinpopa merged 28 commits intomainfrom
branch/push-utqwyssyttom

Conversation

@madalinpopa
Copy link
Copy Markdown
Owner

No description provided.

saveWithExecutor

Wrap errors with context for better debugging. Extract saveWithExecutor
to support custom DB executors.
Add month parsing to ensure valid input before querying groups.
Group create, update, and delete now use unit-of-work transactions for
consistency and rollback on error.
Refactor tests to use mock UnitOfWork with transaction
repositories, ensuring commit is called and repository
methods are invoked within transaction context.
Ensures user creation is atomic by using a unit of work transaction
during registration.
Ensures expense updates are atomic by using a unit of work transaction.
Rollback is attempted on error or failed commit.
Ensures expense deletions are atomic and consistent by using a
transactional unit of work.
Ensures income creation is atomic by using a transaction. Rolls back
on error to maintain data integrity.
- Add icon and ARIA attributes to error alerts for better accessibility
- Enhance dark mode support for error and field error components
- Refine error component styling for consistency
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @madalinpopa, 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 primarily focuses on enhancing data consistency and reliability across the application by refactoring all use cases to strictly adhere to the Unit of Work pattern. This change ensures that all database operations within a single business transaction are properly committed or rolled back together. Alongside this significant architectural improvement, several repository methods were optimized for clarity and security, and minor UI adjustments were made to improve error presentation.

Highlights

  • Unit of Work (UOW) Enforcement: All use cases (Auth, Category, Expense, Group, Income) have been refactored to explicitly use the Unit of Work pattern for data modification operations, ensuring transactional integrity.
  • Repository Improvements: Several repository methods received minor improvements, including better error handling, code refactoring for reusability, and a security enhancement in ExpenseRepository to prevent cross-user category reassignments.
  • Testing Updates: Corresponding test files for use cases and repositories have been updated to reflect the new transactional flow and validate the added security and error handling.
  • UI Component Refinements: Shared UI components for error messages were updated with improved styling and visual cues (icons) for better user experience.
Changelog
  • internal/infrastructure/storage/sqlite/expense_repository.go
    • Formatted FindByID arguments for readability.
    • Added a security check to ReassignCategoryFromMonth to prevent cross-user category reassignments.
  • internal/infrastructure/storage/sqlite/expense_repository_test.go
    • Added a test case to verify ReassignCategoryFromMonth prevents reassignments to other users' categories.
  • internal/infrastructure/storage/sqlite/income_repository.go
    • Refactored FindByUserID and FindByUserIDAndMonth to utilize a new shared fetchIncomes helper function.
  • internal/infrastructure/storage/sqlite/tracking_repository.go
    • Introduced a saveWithExecutor helper to enable Save operations within a transaction.
    • Enhanced error messages for various repository operations to provide more context.
    • Added validation for month parsing in FindByUserIDAndMonth.
  • internal/infrastructure/storage/sqlite/tracking_repository_test.go
    • Added a test case for FindByUserIDAndMonth to handle invalid month inputs.
  • internal/usecase/auth_usecase.go
    • Implemented Unit of Work for the Register method to ensure transactional user creation.
  • internal/usecase/auth_usecase_test.go
    • Updated mocks to support the new Unit of Work pattern for Register method tests.
  • internal/usecase/category_usecase.go
    • Integrated Unit of Work into Create, Update, and Delete methods for category management.
  • internal/usecase/category_usecase_test.go
    • Updated mocks for category use case tests to reflect Unit of Work implementation, including scenarios for transaction rollback.
  • internal/usecase/expense_usecase.go
    • Applied Unit of Work to Create, Update, and Delete methods for expense management.
  • internal/usecase/expense_usecase_test.go
    • Updated mocks for expense use case tests to support the Unit of Work pattern.
  • internal/usecase/group.go
    • Implemented Unit of Work for Create, Update, and Delete methods for group management.
  • internal/usecase/group_usecase_test.go
    • Updated mocks for group use case tests to support the Unit of Work pattern.
  • internal/usecase/income_usecase.go
    • Applied Unit of Work to Create, Update, and Delete methods for income management.
  • internal/usecase/income_usecase_test.go
    • Updated mocks for income use case tests to support the Unit of Work pattern.
  • ui/templates/components/shared.templ
    • Removed redundant import statements.
    • Enhanced error message display in NonFieldErrors and FieldErrorInline components with improved styling and an icon.
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
Copy Markdown

@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 pull request introduces a significant refactoring by consistently applying the Unit of Work pattern across various use cases (Auth, Category, Expense, and Group). This change greatly enhances transactional integrity, ensuring that all related repository operations within a use case are committed or rolled back atomically. Additionally, a crucial security enhancement was implemented in the SQLiteExpenseRepository to prevent reassigning categories to another user's category, which is a valuable improvement. The associated test cases have been updated and expanded to cover the new transactional logic and the security fix, demonstrating thoroughness. Minor stylistic improvements were also made in the UI components, enhancing the user experience. Overall, this is a well-executed and impactful refactoring that improves both the robustness and security of the application.

@madalinpopa madalinpopa merged commit 44ed32a into main Feb 10, 2026
6 checks passed
@madalinpopa madalinpopa deleted the branch/push-utqwyssyttom branch February 10, 2026 19:42
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