Exchange Rate Provider - Backend Task - Fernando Álvarez Naval #676
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
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
Possible improvements