Skip to content

Conversation

@gustaavik
Copy link
Member

This pull request introduces multi-currency support to the system, enabling products, variants, and prices to be managed in multiple currencies. It includes updates to configuration, documentation, and use cases to support this functionality. The most significant changes include adding a default currency configuration, extending the product and currency use cases, and updating the API documentation to reflect the new features.

Configuration Updates

  • Added a new DefaultCurrency field to the Config struct in config/config.go and updated the LoadConfig function to load this value from the environment. A validation ensures that DEFAULT_CURRENCY is provided. [1] [2] [3]

API Documentation Updates

  • Added a new docs/currency_api_examples.md file with detailed examples for currency-related API endpoints, including listing, creating, updating, and deleting currencies, as well as converting amounts.
  • Updated docs/product_api_examples.md to include multi-currency support, such as specifying currency_prices when creating or updating products and variants, and using currency query parameters to retrieve prices in specific currencies. [1] [2] [3] [4] [5] [6] [7]

Use Case Enhancements

  • Added a new CurrencyUseCase in internal/application/usecase/currency_usecase.go to handle currency-related operations, such as creating, updating, deleting, and converting currencies.
  • Extended the ProductUseCase in internal/application/usecase/product_usecase.go to support multi-currency prices for products and variants. This includes validating currencies and processing currency_prices during product creation. [1] [2]

gustaavik and others added 5 commits May 6, 2025 00:44
…onality

- Implemented CurrencyUseCase for managing currencies, including creation, updating, deletion, and retrieval of currencies.
- Added CurrencyHandler for handling HTTP requests related to currencies.
- Introduced new database tables for currencies, product prices, and product variant prices.
- Updated product handler to support fetching products with specific currency prices.
- Added routes for currency management in the API server.
- Created migrations for adding currency support to the database.
- Developed mock repository for testing currency-related functionalities.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
feat: Add currency support with CRUD operations
@gustaavik gustaavik requested a review from Copilot May 9, 2025 10:42
Copy link
Contributor

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 introduces multi-currency support by adding a default currency configuration in the system, expanding currency-related use cases and handlers, and updating API documentation and tests. Key changes include configuration updates to load and validate a default currency; new currency API endpoints and a dedicated CurrencyUseCase; and extending product and variant use cases to handle multiple currency prices.

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
migrations/000014_add_currency_support.down.sql SQL script to remove currency tables, indexes, and constraints for rollback purposes
internal/interfaces/api/server.go Adds public and admin currency routes to the API server
internal/interfaces/api/handler/{product,currency}_handler.go Extends product and creates currency HTTP handlers for multi-currency operations
internal/infrastructure/container/* Updates dependency injection to include the new CurrencyUseCase and CurrencyHandler
internal/domain/* Adds new currency and price entity definitions
internal/application/usecase/* Updates product and currency use cases to process currency prices and support multi-currency queries
docs/* Updates API examples to include multi-currency parameters and payloads
config/config.go Adds a new DefaultCurrency field and loads it from the environment
Comments suppressed due to low confidence (2)

internal/infrastructure/container/usecase_provider.go:18

  • [nitpick] Consider renaming 'CurrencyUsecase' to 'CurrencyUseCase' for consistency with other method names and common CamelCase conventions.
CurrencyUsecase() *usecase.CurrencyUseCase

internal/application/usecase/product_usecase.go:667

  • [nitpick] Verify that the rounding and conversion logic for min/max prices—when converting from a non-default currency to the default currency—is performing as expected, ensuring no unintended precision loss in search filtering.
if input.CurrencyCode != "" && input.CurrencyCode != defaultCurr.Code {

@gustaavik gustaavik merged commit 4ca9125 into main May 9, 2025
4 checks passed
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.

2 participants