Skip to content
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

ExchangeRateUpdater: A Lightweight .NET API for Retrieving CNB Exchange Rates - Vladimir Vikhanov #692

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Woptope
Copy link

@Woptope Woptope commented Mar 5, 2025

Exchange Rate Provider - Backend Task

This pull request introduces a .NET 8 API application that fetches and exposes exchange rates from the Czech National Bank (CNB).
It provides a single endpoint that accepts a date and one or more currency codes, returning the exchange rates relative to CZK.

The solution follows clean architecture principles, ensuring separation of concerns across different layers:

  • Core: Business logic, domain models, CNB client, and provider logic.
  • API: Controllers, DTOs, Swagger integration, and logging configuration.
  • Tests: Unit tests with mocked HTTP responses to validate different scenarios.

Solution Highlights

Separation of Concerns

  • Core: Contains domain models (Currency, ExchangeRate), CNB client, and provider logic.
  • API: Handles controllers, DTOs, Swagger integration, and logging setup.
  • Tests: Includes unit tests that mock CNB API responses.

Logging & Configuration

  • Uses Serilog for structured logging.
  • Logs to console, rolling file, and Visual Studio Debug window.
  • Reads base URL from appsettings.json via the strongly-typed CnbOptions class.

Swagger / OpenAPI Integration

  • Endpoints and DTOs are annotated with [SwaggerOperation] and [SwaggerSchema] for clear documentation.
  • Supports testing via Swagger UI without external tools.

Unit Testing & Error Handling

  • Dedicated test project with:
    • Mocked CNB responses for valid JSON, invalid JSON, and 500 errors.
    • Coverage of both happy path and edge cases.

Extensibility & Future Improvements

  • Security: Add authentication & authorization for sensitive operations.
  • Caching: Implement Redis or another caching layer to improve performance.
  • New Features: Support for exporting results (CSV/Excel) and multi-currency transformations.
  • Extended Endpoints: Expand API functionality, e.g., adding historical exchange rate retrieval.
  • Increased Test Coverage: Extend unit tests to cover more edge cases, including extreme date ranges.
  • Logging Enhancements: Integrate external log aggregators for better observability.

Usage

  1. Run the API and navigate to /swagger.
  2. Provide:
    • Date in YYYY-MM-DD format.
    • Comma-separated currency codes (e.g., "USD,EUR,CZK").
  3. The API returns exchange rates in JSON format.

Why This Approach?

  • Simplicity & Focus: Retrieves real exchange rates from CNB, structures them into domain models, and exposes them via a clean, well-documented API.
  • Scalability & Maintainability: SOLID design principles ensure clarity and long-term maintainability.

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