Skip to content

Added EUR support, fallback provider, caching, and currency tracking.#2

Open
dimitriyTsemma wants to merge 4 commits intoCorpEdward:mainfrom
dimitriyTsemma:feature/task-0001-euro-exchange
Open

Added EUR support, fallback provider, caching, and currency tracking.#2
dimitriyTsemma wants to merge 4 commits intoCorpEdward:mainfrom
dimitriyTsemma:feature/task-0001-euro-exchange

Conversation

@dimitriyTsemma
Copy link

Summary

This PR implements EUR currency support, adds a fallback exchange rate provider, implements smart caching with daily invalidation, and tracks catalog currency usage via asynchronous jobs.

Changes

🆕 New Features

  1. EUR Currency Support

    • Added GET /api/catalog/EUR endpoint for product catalog with EUR prices
    • Added GET /api/exchangeRate/EUR endpoint for EUR/UAH exchange rate
    • Updated validation to accept usd, uah, and eur currencies
  2. Fallback Exchange Rate Provider

    • Integrated Open Exchange Rates API (https://open.er-api.com/v6/latest/UAH) as secondary provider
    • Implemented automatic fallback using Chain of Responsibility pattern
    • Primary: NBU API, Fallback: Open Exchange Rates API
  3. Smart Caching

    • 10-minute TTL for exchange rates
    • Automatic cache invalidation on a new calendar day
    • Configurable cache driver (Redis/Memcached/Database)
    • Implemented via Decorator pattern
  4. Currency Usage Tracking

    • Asynchronous job dispatched on every catalog request
    • Tracks: currency, timestamp, IP address, user agent
    • Database table: catalog_currency_usage with indexed columns
  5. Configuration-Driven Architecture

    • Created config/currency.php for provider selection
    • Swap providers without code changes via environment variables
    • Configurable caching behavior

🏗️ Architecture & Design Patterns

  • Strategy Pattern — CurrencyRateProviderInterface for interchangeable providers
  • Chain of Responsibility — ChainOfResponsibilityProvider for automatic fallback
  • Decorator Pattern — CachedCurrencyRateProvider for transparent caching
  • Dependency Inversion — Application depends on abstractions, not implementations
  • SOLID Principles — Applied throughout the codebase

Test Plan

✅ All Tests Passing

php artisan test

@dimitriyTsemma dimitriyTsemma force-pushed the feature/task-0001-euro-exchange branch from e132ba3 to 456a32f Compare March 14, 2026 19:05
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