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

Exchange Rate Provider - Backend Task - Fernando Álvarez Naval #676

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

Conversation

nandonaval
Copy link

Overview

Approach to solving the backend task consisting on the creation of a tool that allows obtaining Exchange Rates from the Czech National Bank.

Solution

The solution is an API with one endpoint that takes an object as a parameter containing the date and the currency combinations you want to get the exchanche (CNB API currently only retrives exchanges from CZK to foreign currencies, but the api allows multicurrencies operations in case the bank source changes or even use a different source).

My approach was to keep it simple since the requirement was simple and specific.
I used different layers for different purposes (API, Business and Data) which results in better separation of responsibilities, maintenance and scalability.

The solution uses logging (ILogger from .NET) for the logging of events and in memory caché (also from .NET) to cache the exchanges retrieved from the bank for a particular date in order to be consumed everytime this same date is requested.

The solution also includes a unit test project that covers some of the most common use cases.

The decision to create an API is based on the possibility of being consumed by different applications. As a first approach, the API does not have security since the information consumed from the CNB API is public, so it is not appropriate to secure it, but it is a feature that could be included as a future improvement in case new operations are added that require it.

Use

The solution uses swagger so it can be executed from there or using some other tool such as Postman.

image

A request can be send to the only endpoint available (POST api/exchangerates/getExchangeRates) using as a parameter the type of object described on Swagger:

{
  "date": "2025-01-17",
  "exchangeRatesDetails": [
    {
      "sourceCurrency": {
        "code": "CZK"
      },
      "targetCurrency": {
        "code": "USD"
      }
    }
  ]
}

The decision of using POST is based on the need of send and object as an argument to the endpoint.
The expected output is a list of exchange rate object containing 3 properties:

-Currencies (string) => combination of source and target currency requested
-Value (decimal) => value of the exchange rate
-Date (DateTime) => valid date for the exchange rate

[
    {
        "currencies": "CZK / CAD",
        "value": 17.008,
        "date": "2025-01-17T00:00:00"
    },
    {
        "currencies": "CZK / HKD",
        "value": 3.152,
        "date": "2025-01-17T00:00:00"
    },
    {
        "currencies": "CZK / USD",
        "value": 24.542,
        "date": "2025-01-17T00:00:00"
    }
]

Possible improvements

  1. Add security
  2. Add distributed caché like Redis
  3. Add some other endpoint for useful operations such as download the results to a file
  4. Add some external logging framework to save logs into a file
  5. Add more testing coverage

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