diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
new file mode 100644
index 000000000..1480c76ac
--- /dev/null
+++ b/.vs/VSWorkspaceState.json
@@ -0,0 +1,7 @@
+{
+ "ExpandedNodes": [
+ ""
+ ],
+ "SelectedNode": "\\Mews.ExchangeRateMonitor.sln",
+ "PreviewInSolutionExplorer": false
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/.dockerignore b/jobs/Backend/Task/.dockerignore
new file mode 100644
index 000000000..fe1152bdb
--- /dev/null
+++ b/jobs/Backend/Task/.dockerignore
@@ -0,0 +1,30 @@
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
+!**/.gitignore
+!.git/HEAD
+!.git/config
+!.git/packed-refs
+!.git/refs/heads/**
\ No newline at end of file
diff --git a/jobs/Backend/Task/.gitattributes b/jobs/Backend/Task/.gitattributes
new file mode 100644
index 000000000..1ff0c4230
--- /dev/null
+++ b/jobs/Backend/Task/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/jobs/Backend/Task/.gitignore b/jobs/Backend/Task/.gitignore
new file mode 100644
index 000000000..283883a3b
--- /dev/null
+++ b/jobs/Backend/Task/.gitignore
@@ -0,0 +1,366 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# dockerdata
+docker_data/
\ No newline at end of file
diff --git a/jobs/Backend/Task/Currency.cs b/jobs/Backend/Task/Currency.cs
deleted file mode 100644
index f375776f2..000000000
--- a/jobs/Backend/Task/Currency.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace ExchangeRateUpdater
-{
- public class Currency
- {
- public Currency(string code)
- {
- Code = code;
- }
-
- ///
- /// Three-letter ISO 4217 code of the currency.
- ///
- public string Code { get; }
-
- public override string ToString()
- {
- return Code;
- }
- }
-}
diff --git a/jobs/Backend/Task/Directory.Build.props b/jobs/Backend/Task/Directory.Build.props
new file mode 100644
index 000000000..1a065d6d4
--- /dev/null
+++ b/jobs/Backend/Task/Directory.Build.props
@@ -0,0 +1,6 @@
+
+
+ enable
+ true
+
+
\ No newline at end of file
diff --git a/jobs/Backend/Task/Directory.Packages.props b/jobs/Backend/Task/Directory.Packages.props
new file mode 100644
index 000000000..731bd3b54
--- /dev/null
+++ b/jobs/Backend/Task/Directory.Packages.props
@@ -0,0 +1,36 @@
+
+
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jobs/Backend/Task/ExchangeRate.cs b/jobs/Backend/Task/ExchangeRate.cs
deleted file mode 100644
index 58c5bb10e..000000000
--- a/jobs/Backend/Task/ExchangeRate.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-namespace ExchangeRateUpdater
-{
- public class ExchangeRate
- {
- public ExchangeRate(Currency sourceCurrency, Currency targetCurrency, decimal value)
- {
- SourceCurrency = sourceCurrency;
- TargetCurrency = targetCurrency;
- Value = value;
- }
-
- public Currency SourceCurrency { get; }
-
- public Currency TargetCurrency { get; }
-
- public decimal Value { get; }
-
- public override string ToString()
- {
- return $"{SourceCurrency}/{TargetCurrency}={Value}";
- }
- }
-}
diff --git a/jobs/Backend/Task/ExchangeRateProvider.cs b/jobs/Backend/Task/ExchangeRateProvider.cs
deleted file mode 100644
index 6f82a97fb..000000000
--- a/jobs/Backend/Task/ExchangeRateProvider.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-
-namespace ExchangeRateUpdater
-{
- public class ExchangeRateProvider
- {
- ///
- /// Should return exchange rates among the specified currencies that are defined by the source. But only those defined
- /// by the source, do not return calculated exchange rates. E.g. if the source contains "CZK/USD" but not "USD/CZK",
- /// do not return exchange rate "USD/CZK" with value calculated as 1 / "CZK/USD". If the source does not provide
- /// some of the currencies, ignore them.
- ///
- public IEnumerable GetExchangeRates(IEnumerable currencies)
- {
- return Enumerable.Empty();
- }
- }
-}
diff --git a/jobs/Backend/Task/ExchangeRateUpdater.csproj b/jobs/Backend/Task/ExchangeRateUpdater.csproj
deleted file mode 100644
index 2fc654a12..000000000
--- a/jobs/Backend/Task/ExchangeRateUpdater.csproj
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
- Exe
- net6.0
-
-
-
\ No newline at end of file
diff --git a/jobs/Backend/Task/ExchangeRateUpdater.sln b/jobs/Backend/Task/ExchangeRateUpdater.sln
deleted file mode 100644
index 89be84daf..000000000
--- a/jobs/Backend/Task/ExchangeRateUpdater.sln
+++ /dev/null
@@ -1,22 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25123.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExchangeRateUpdater", "ExchangeRateUpdater.csproj", "{7B2695D6-D24C-4460-A58E-A10F08550CE0}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {7B2695D6-D24C-4460-A58E-A10F08550CE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7B2695D6-D24C-4460-A58E-A10F08550CE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7B2695D6-D24C-4460-A58E-A10F08550CE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7B2695D6-D24C-4460-A58E-A10F08550CE0}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Abstractions/IApiEndpoint.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Abstractions/IApiEndpoint.cs
new file mode 100644
index 000000000..42f06be2c
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Abstractions/IApiEndpoint.cs
@@ -0,0 +1,15 @@
+using Microsoft.AspNetCore.Builder;
+
+namespace Mews.ExchangeRateMonitor.Common.API.Abstractions;
+
+///
+/// Represents an interface defining the contract for mapping API endpoints into a web application.
+///
+public interface IApiEndpoint
+{
+ ///
+ /// Maps the API endpoint for the specified web application instance.
+ ///
+ /// The web application instance where the API endpoint will be mapped.
+ void MapEndpoint(WebApplication app);
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/DependencyInjection.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/DependencyInjection.cs
new file mode 100644
index 000000000..0054f3f28
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/DependencyInjection.cs
@@ -0,0 +1,131 @@
+using Mews.ExchangeRateMonitor.Common.API.ErrorHandling;
+using Mews.ExchangeRateMonitor.Common.API.RateLimiting;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http.Json;
+using Microsoft.AspNetCore.RateLimiting;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.OpenApi.Models;
+using Serilog;
+using System.Text.Json.Serialization;
+using System.Threading.RateLimiting;
+
+namespace Mews.ExchangeRateMonitor.Common.API;
+
+public static class DependencyInjection
+{
+ ///
+ /// Adds core web API infrastructure services
+ ///
+ ///
+ ///
+ public static IServiceCollection AddCoreWebApiInfrastructure(this IServiceCollection services)
+ {
+ services.AddSwagger();
+ services.AddRateLimiting();
+ services.AddGlobalExceptionHadnler();
+ services.AddJsonConfigurations();
+ services.AddCors(o => o.AddPolicy("dev", p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
+ return services;
+ }
+
+ ///
+ /// Adds global exception handler and problem details services
+ ///
+ ///
+ ///
+ public static IServiceCollection AddGlobalExceptionHadnler(this IServiceCollection services)
+ {
+ services
+ .AddExceptionHandler()
+ .AddProblemDetails();
+
+ return services;
+
+ }
+
+ ///
+ /// Adds rate limiting policy
+ ///
+ ///
+ ///
+ public static IServiceCollection AddRateLimiting(this IServiceCollection services)
+ {
+ services.AddRateLimiter(options =>
+ {
+ options.AddFixedWindowLimiter(AppRateLimiting.GlobalRateLimitPolicy, opt =>
+ {
+ opt.Window = TimeSpan.FromMinutes(1); // Time window of 1 minute
+ opt.PermitLimit = 100; // Allow 100 requests per minute
+ opt.QueueLimit = 2; // Queues 2 additional requests if the limit is reached
+ opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
+ });
+ });
+
+ return services;
+ }
+
+ ///
+ /// Configures Swagger generation
+ ///
+ ///
+ ///
+ public static IServiceCollection AddSwagger(this IServiceCollection services)
+ {
+ services
+ .AddEndpointsApiExplorer()
+ .AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
+ });
+
+ return services;
+ }
+
+ ///
+ /// REgiser JSON configurations, like enum to string conversion
+ ///
+ ///
+ ///
+ public static IServiceCollection AddJsonConfigurations(this IServiceCollection services)
+ {
+ services.Configure(opt =>
+ {
+ opt.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
+ });
+
+ return services;
+ }
+
+ ///
+ /// Adds logging to the web application builder.
+ ///
+ ///
+ public static void AddCoreHostLogging(this WebApplicationBuilder builder)
+ {
+ builder.Host.UseSerilog((context, loggerConfig) =>
+ loggerConfig.ReadFrom.Configuration(context.Configuration));
+ }
+
+ ///
+ /// Adds swagger and swagger UI
+ ///
+ ///
+ ///
+ public static IApplicationBuilder UseSwaggerExt(this IApplicationBuilder app)
+ {
+ app.UseSwagger();
+ app.UseSwaggerUI();
+ return app;
+ }
+
+ ///
+ /// Adds rate limiting
+ ///
+ ///
+ ///
+ public static IApplicationBuilder UseAppRateLimiter(this IApplicationBuilder app)
+ {
+ app.UseRateLimiter();
+ return app;
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/ErrorHandling/GlobalExceptionHandler.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/ErrorHandling/GlobalExceptionHandler.cs
new file mode 100644
index 000000000..6bbcc32f2
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/ErrorHandling/GlobalExceptionHandler.cs
@@ -0,0 +1,38 @@
+using Microsoft.AspNetCore.Diagnostics;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+
+namespace Mews.ExchangeRateMonitor.Common.API.ErrorHandling;
+
+///
+/// Global exception handler that logs unhandled exceptions and returns a 500 Internal Server Error response with problem details.
+///
+///
+///
+internal sealed class GlobalExceptionHandler(
+ IProblemDetailsService problemDetailsService,
+ ILogger logger) : IExceptionHandler
+{
+ public async ValueTask TryHandleAsync(
+ HttpContext httpContext,
+ Exception exception,
+ CancellationToken cancellationToken)
+ {
+ logger.LogError(exception, "Unhandled exception occurred while processing request");
+
+ httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
+
+ return await problemDetailsService.TryWriteAsync(new ProblemDetailsContext
+ {
+ HttpContext = httpContext,
+ Exception = exception,
+ ProblemDetails = new ProblemDetails
+ {
+ Type = exception.GetType().Name,
+ Title = "An error occured while processing your request.",
+ Detail = exception.Message
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/EndpointResultsExtensions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/EndpointResultsExtensions.cs
new file mode 100644
index 000000000..512e3799d
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/EndpointResultsExtensions.cs
@@ -0,0 +1,39 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+using Microsoft.AspNetCore.Http;
+using IResult = Microsoft.AspNetCore.Http.IResult;
+
+namespace Mews.ExchangeRateMonitor.Common.API.Extensions;
+
+public static class EndpointResultsExtensions
+{
+ public static IResult ToProblem(this List errors)
+ {
+ if (errors.Count is 0)
+ {
+ return Results.Problem();
+ }
+
+ return CreateProblem(errors);
+ }
+
+ private static IResult CreateProblem(List errors)
+ {
+ var statusCode = errors.First().Type switch
+ {
+ ErrorType.Conflict => StatusCodes.Status409Conflict,
+ ErrorType.Validation => StatusCodes.Status400BadRequest,
+ ErrorType.NotFound => StatusCodes.Status404NotFound,
+ ErrorType.Unauthorized => StatusCodes.Status401Unauthorized,
+ ErrorType.Forbidden => StatusCodes.Status403Forbidden,
+
+ ErrorType.Failure => StatusCodes.Status400BadRequest,
+ ErrorType.Unexpected => StatusCodes.Status400BadRequest,
+ ErrorType.Custom => StatusCodes.Status400BadRequest,
+
+ _ => StatusCodes.Status500InternalServerError
+ };
+
+ return Results.ValidationProblem(errors.ToDictionary(k => k.Code, v => new[] { v.Description }),
+ statusCode: statusCode);
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/MapEndpointExtensions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/MapEndpointExtensions.cs
new file mode 100644
index 000000000..6cfb913ef
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Extensions/MapEndpointExtensions.cs
@@ -0,0 +1,46 @@
+using Mews.ExchangeRateMonitor.Common.API.Abstractions;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Mews.ExchangeRateMonitor.Common.API.Extensions;
+
+public static class MapEndpointExtensions
+{
+ ///
+ /// Registers all API endpoints implementing from the assembly containing the specified type into the service collection.
+ ///
+ /// The service collection to register the endpoints into.
+ /// A type whose assembly will be scanned for implementations.
+ /// The modified service collection with registered endpoints.
+ public static IServiceCollection RegisterApiEndpointsFromAssemblyContaining(this IServiceCollection services, Type marker)
+ {
+ var assembly = marker.Assembly;
+ var endpointTypes = assembly.GetTypes()
+ .Where(t => t.IsAssignableTo(typeof(IApiEndpoint)) && t is { IsClass: true, IsAbstract: false, IsInterface: false });
+
+ var serviceDescriptors = endpointTypes
+ .Select(type => ServiceDescriptor.Transient(typeof(IApiEndpoint), type))
+ .ToArray();
+
+ services.TryAddEnumerable(serviceDescriptors);
+ return services;
+ }
+
+ ///
+ /// Maps all registered API endpoints implementing the interface to the specified web application.
+ ///
+ /// The instance to which the endpoints will be mapped.
+ /// The same instance to allow for method chaining.
+ public static WebApplication MapApiEndpoints(this WebApplication app)
+ {
+ var endpoints = app.Services.GetRequiredService>();
+
+ foreach (var endpoint in endpoints)
+ {
+ endpoint.MapEndpoint(app);
+ }
+
+ return app;
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Mews.ExchangeRateMonitor.Common.API.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Mews.ExchangeRateMonitor.Common.API.csproj
new file mode 100644
index 000000000..cf102b94c
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/Mews.ExchangeRateMonitor.Common.API.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/RateLimiting/RateLimiting.Constants.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/RateLimiting/RateLimiting.Constants.cs
new file mode 100644
index 000000000..23368e157
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.API/RateLimiting/RateLimiting.Constants.cs
@@ -0,0 +1,6 @@
+namespace Mews.ExchangeRateMonitor.Common.API.RateLimiting;
+
+public static class AppRateLimiting
+{
+ public const string GlobalRateLimitPolicy = "GlobalRateLimitPolicy";
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/HandlerRegistrationExtensions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/HandlerRegistrationExtensions.cs
new file mode 100644
index 000000000..a22c576b7
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/HandlerRegistrationExtensions.cs
@@ -0,0 +1,42 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Handlers;
+using Microsoft.Extensions.DependencyInjection;
+using System.Reflection;
+
+namespace Mews.ExchangeRateMonitor.Common.Application.Extensions;
+
+public static class HandlerRegistrationExtensions
+{
+ ///
+ /// Registers all handlers from the assembly containing the specified type
+ ///
+ /// The service collection
+ /// A type from the assembly where handlers are located
+ /// The service collection for chaining
+ public static IServiceCollection RegisterHandlersFromAssemblyContaining(this IServiceCollection services, Type marker)
+ {
+ var assembly = marker.Assembly;
+
+ RegisterCommandHandlers(services, assembly);
+
+ return services;
+ }
+
+ private static void RegisterCommandHandlers(IServiceCollection services, Assembly assembly)
+ {
+ var handlerTypes = assembly.GetTypes()
+ .Where(t => t is { IsClass: true, IsAbstract: false }
+ && t.IsAssignableTo(typeof(IHandler)))
+ .ToList();
+
+ foreach (var implementationType in handlerTypes)
+ {
+ var interfaceType = implementationType.GetInterfaces()
+ .FirstOrDefault(i => i != typeof(IHandler) && i.IsAssignableTo(typeof(IHandler)));
+
+ if (interfaceType is not null)
+ {
+ services.AddScoped(interfaceType, implementationType);
+ }
+ }
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/ValidationExtensions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/ValidationExtensions.cs
new file mode 100644
index 000000000..20e8bb0a8
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Extensions/ValidationExtensions.cs
@@ -0,0 +1,28 @@
+using Microsoft.Extensions.Logging;
+using FluentValidation.Results;
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+namespace Mews.ExchangeRateMonitor.Common.Application.Extensions;
+
+public static class ValidationExtensions
+{
+ public static List ToFormattedErrorMessages(this ValidationResult validationResult)
+ {
+ return validationResult.Errors
+ .Select(e => $"{e.PropertyName}: {e.ErrorMessage}")
+ .ToList();
+ }
+ public static List ToDomainErrors(this ValidationResult validationResult, string errorPrefix)
+ {
+ return validationResult.Errors
+ .Select(x => Error.Validation(errorPrefix, $"{x.PropertyName}:{x.ErrorMessage}"))
+ .ToList();
+ }
+
+
+ public static void LogValidationErrors(this ILogger logger, ValidationResult validationResult, string contextMessage)
+ {
+ var validationErrors = validationResult.ToFormattedErrorMessages();
+ logger.LogWarning("{ContextMessage}: {Errors}", contextMessage, string.Join(", ", validationErrors));
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Mews.ExchangeRateMonitor.Common.Application.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Mews.ExchangeRateMonitor.Common.Application.csproj
new file mode 100644
index 000000000..9c4511ba7
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Application/Mews.ExchangeRateMonitor.Common.Application.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Handlers/IHandler.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Handlers/IHandler.cs
new file mode 100644
index 000000000..adcad23e5
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Handlers/IHandler.cs
@@ -0,0 +1,6 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Handlers;
+
+///
+/// Marker interface for all handlers in the application
+///
+public interface IHandler;
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Mews.ExchangeRateMonitor.Common.Domain.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Mews.ExchangeRateMonitor.Common.Domain.csproj
new file mode 100644
index 000000000..125f4c93b
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Mews.ExchangeRateMonitor.Common.Domain.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Error.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Error.cs
new file mode 100644
index 000000000..3f445efa3
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Error.cs
@@ -0,0 +1,74 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+public readonly record struct Error
+{
+ private Error(string code, string description, ErrorType type)
+ {
+ Code = code;
+ Description = description;
+ Type = type;
+ }
+
+ private Error(string code, string description, int numericType)
+ {
+ Code = code;
+ Description = description;
+ NumericType = numericType;
+
+ Type = ErrorType.Custom;
+ }
+
+ ///
+ /// Gets the unique error code.
+ ///
+ public string Code { get; }
+
+ ///
+ /// Gets the error description.
+ ///
+ public string Description { get; }
+
+ ///
+ /// Gets the error type.
+ ///
+ public ErrorType Type { get; }
+
+ ///
+ /// Gets the numeric value of the type.
+ ///
+ public int NumericType { get; }
+
+ public static Error Failure(string code, string description) =>
+ new(code, description, ErrorType.Failure);
+
+ public static Error Unexpected(string code, string description) =>
+ new(code, description, ErrorType.Unexpected);
+
+ public static Error Validation(string code, string description) =>
+ new(code, description, ErrorType.Validation);
+
+ public static Error Conflict(string code, string description) =>
+ new(code, description, ErrorType.Conflict);
+
+ public static Error NotFound(string code, string description) =>
+ new(code, description, ErrorType.NotFound);
+
+ public static Error Unauthorized(string code, string description) =>
+ new(code, description, ErrorType.Unauthorized);
+
+ public static Error Forbidden(string code, string description) =>
+ new(code, description, ErrorType.Forbidden);
+
+ public static Error Custom(int type, string code, string description) =>
+ new(code, description, type);
+
+ public bool Equals(Error other)
+ {
+ return Type == other.Type &&
+ NumericType == other.NumericType &&
+ Code == other.Code &&
+ Description == other.Description;
+ }
+
+ public override int GetHashCode() => HashCode.Combine(Code, Description, Type, NumericType);
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/ErrorType.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/ErrorType.cs
new file mode 100644
index 000000000..63dfda703
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/ErrorType.cs
@@ -0,0 +1,14 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+public enum ErrorType
+{
+ Failure,
+ Unexpected,
+ Validation,
+ Conflict,
+ NotFound,
+ Unauthorized,
+ Forbidden,
+ Canceled,
+ Custom
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/IAppResult.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/IAppResult.cs
new file mode 100644
index 000000000..4c9cc12b5
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/IAppResult.cs
@@ -0,0 +1,35 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+///
+/// Represents a result of an operation which encapsulates either a success or an error state.
+///
+public interface IAppResult
+{
+ ///
+ /// Gets the collection of errors associated with the operation result.
+ ///
+ List? Errors { get; }
+
+ ///
+ /// Indicates whether the operation result represents a success state.
+ ///
+ bool IsSuccess { get; }
+
+ ///
+ /// Gets a value indicating whether the result represents an error state.
+ ///
+ bool IsError { get; }
+}
+
+///
+/// Represents the result of an operation with the ability to define a value type
+/// and encapsulate success or error states.
+///
+/// The type of the value returned on a successful result.
+public interface IAppResult : IAppResult
+{
+ ///
+ /// Gets the value associated with the operation result. This can represent the successful outcome of the operation.
+ ///
+ TValue? Value { get; }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.ImplicitConverters.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.ImplicitConverters.cs
new file mode 100644
index 000000000..5e79572f3
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.ImplicitConverters.cs
@@ -0,0 +1,50 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+///
+/// Represents the outcome of an operation, encapsulating either a value of type
+/// or one or more errors indicating failure.
+///
+/// The type of the value held by the result when the operation is successful.
+///
+/// The type provides a mechanism to represent both successful outcomes,
+/// which carry a value of type , and errors, which can be encapsulated in
+/// , a collection of , or both. This abstraction aids in
+/// avoiding exceptions for flow control and makes error handling explicit and structured.
+///
+public readonly partial record struct Result
+{
+ ///
+ /// Defines an implicit conversion operator that constructs a
+ /// from a value of type .
+ ///
+ /// The value of type used to create a successful result.
+ /// A new instance representing a successful outcome with the provided value.
+ public static implicit operator Result(TValue value) => new(value);
+
+ ///
+ /// Defines an implicit conversion operator that constructs a
+ /// from an instance.
+ ///
+ /// The instance encapsulating the error information
+ /// used to create a failure result.
+ /// A new instance representing a failure with the provided error.
+ public static implicit operator Result(Error error) => new(error);
+
+ ///
+ /// Defines implicit conversion operators for the struct.
+ ///
+ ///
+ /// These operators allow for implicit conversion between , ,
+ /// lists of , and arrays of into a object.
+ ///
+ ///
+ /// This conversion simplifies the process of creating instances of
+ /// by allowing direct assignment from supported types.
+ ///
+ public static implicit operator Result(List errors) => new(errors);
+
+ ///
+ /// Provides implicit conversion operators for the type.
+ ///
+ public static implicit operator Result(Error[] errors) => new([.. errors]);
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.cs
new file mode 100644
index 000000000..9c4a2b451
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Domain/Results/Result.cs
@@ -0,0 +1,99 @@
+namespace Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+
+///
+/// Represents the success result of an operation, typically used to indicate that a process has completed successfully without returning a specific value or data.
+///
+public readonly record struct Success;
+
+///
+/// Represents a class containing utility methods for handling operation results.
+///
+public static class Result
+{
+ ///
+ /// Represents a successful operation result.
+ ///
+ public static Success Success => default;
+}
+
+public readonly partial record struct Result : IAppResult
+{
+ private readonly TValue? _value = default;
+
+ private Result(TValue value)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+
+ _value = value;
+ }
+
+ private Result(Error error)
+ {
+ Errors = [error];
+ }
+
+ private Result(List errors)
+ {
+ ArgumentNullException.ThrowIfNull(errors);
+
+ if (errors.Count == 0)
+ {
+ throw new ArgumentException("Cannot create an Result from an empty collection of errors. Provide at least one error.", nameof(errors));
+ }
+
+ Errors = errors;
+ }
+
+ ///
+ /// Gets a value indicating whether the state is a success.
+ ///
+ public bool IsSuccess => Errors is null or [];
+
+ ///
+ /// Gets a value indicating whether the state is error.
+ ///
+ public bool IsError => Errors.Count > 0;
+
+ ///
+ /// Gets the collection of errors.
+ ///
+ public List Errors { get; } = [];
+
+ ///
+ /// Gets the value.
+ ///
+ /// Thrown when no value is present.
+ public TValue? Value
+ {
+ get
+ {
+ if (IsError)
+ {
+ throw new InvalidOperationException("The Value property cannot be accessed when Errors property is not empty. Check IsSuccess or IsError before accessing the Value.");
+ }
+
+ return _value;
+ }
+ }
+
+ ///
+ /// Gets the first error.
+ ///
+ /// Thrown when no errors are present.
+ public Error FirstError
+ {
+ get
+ {
+ if (!IsError)
+ {
+ throw new InvalidOperationException("The FirstError property cannot be accessed when Errors property is empty. Check IsError before accessing FirstError.");
+ }
+
+ return Errors[0];
+ }
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/DependencyInjection.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/DependencyInjection.cs
new file mode 100644
index 000000000..a91e2dddd
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/DependencyInjection.cs
@@ -0,0 +1,40 @@
+using Microsoft.Extensions.DependencyInjection;
+using OpenTelemetry.Resources;
+using OpenTelemetry.Trace;
+
+namespace Mews.ExchangeRateMonitor.Common.Infrastructure;
+
+public static class DependencyInjection
+{
+
+ public static IServiceCollection AddCoreInfrastructure(this IServiceCollection services)
+ {
+ services.AddMemoryCache();
+ services.AddHostOpenTelemetry();
+
+ return services;
+ }
+
+ private static IServiceCollection AddHostOpenTelemetry(
+ this IServiceCollection services,
+ params string[] activityModuleNames)
+ {
+ services
+ .AddOpenTelemetry()
+ .ConfigureResource(resource => resource.AddService("Mews.ExchangeRateMonitor"))
+ .WithTracing(tracing =>
+ {
+ tracing
+ //creates spans(operation activities) for incoming http requests
+ .AddAspNetCoreInstrumentation()
+ //creates spans(operation activities) for outgoing http requests
+ .AddHttpClientInstrumentation()
+ //Sends trace data to an OTLP endpoint (usually an OpenTelemetry Collector).
+ //The collector then forwards it to Jaeger
+ //OTLP exporter config(endpoint, protocol, headers) comes from appsettings.json or env vars
+ .AddOtlpExporter();
+ });
+
+ return services;
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/Mews.ExchangeRateMonitor.Common.Infrastructure.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/Mews.ExchangeRateMonitor.Common.Infrastructure.csproj
new file mode 100644
index 000000000..7cd85d319
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Infrastructure/Mews.ExchangeRateMonitor.Common.Infrastructure.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ErrorTests.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ErrorTests.cs
new file mode 100644
index 000000000..f6e28d43b
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ErrorTests.cs
@@ -0,0 +1,210 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+namespace Mews.ExchangeRateMonitor.Common.Tests.Unit;
+
+public class ErrorTests
+{
+ [Fact]
+ public void Create_ShouldCreateFailureError_WhenUsingFailureFactory()
+ {
+ // Arrange
+ const string code = "Test.Failure";
+ const string description = "Test failure description";
+
+ // Act
+ var error = Error.Failure(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Failure, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateUnexpectedError_WhenUsingUnexpectedFactory()
+ {
+ // Arrange
+ const string code = "Test.Unexpected";
+ const string description = "Test unexpected description";
+
+ // Act
+ var error = Error.Unexpected(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Unexpected, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateValidationError_WhenUsingValidationFactory()
+ {
+ // Arrange
+ const string code = "Test.Validation";
+ const string description = "Test validation description";
+
+ // Act
+ var error = Error.Validation(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Validation, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateConflictError_WhenUsingConflictFactory()
+ {
+ // Arrange
+ const string code = "Test.Conflict";
+ const string description = "Test conflict description";
+
+ // Act
+ var error = Error.Conflict(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Conflict, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateNotFoundError_WhenUsingNotFoundFactory()
+ {
+ // Arrange
+ const string code = "Test.NotFound";
+ const string description = "Test not found description";
+
+ // Act
+ var error = Error.NotFound(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.NotFound, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateUnauthorizedError_WhenUsingUnauthorizedFactory()
+ {
+ // Arrange
+ const string code = "Test.Unauthorized";
+ const string description = "Test unauthorized description";
+
+ // Act
+ var error = Error.Unauthorized(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Unauthorized, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateForbiddenError_WhenUsingForbiddenFactory()
+ {
+ // Arrange
+ const string code = "Test.Forbidden";
+ const string description = "Test forbidden description";
+
+ // Act
+ var error = Error.Forbidden(code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Forbidden, error.Type);
+ }
+
+ [Fact]
+ public void Create_ShouldCreateCustomError_WhenUsingCustomFactory()
+ {
+ // Arrange
+ const string code = "Test.Custom";
+ const string description = "Test custom description";
+ const int customType = 100;
+
+ // Act
+ var error = Error.Custom(customType, code, description);
+
+ // Assert
+ Assert.Equal(code, error.Code);
+ Assert.Equal(description, error.Description);
+ Assert.Equal(ErrorType.Custom, error.Type);
+ Assert.Equal(customType, error.NumericType);
+ }
+
+ [Fact]
+ public void Equals_ShouldReturnTrue_WhenErrorsAreEqual()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code", "Test description");
+ var error2 = Error.Validation("Test.Code", "Test description");
+
+ // Act & Assert
+ Assert.Equal(error1, error2);
+ }
+
+ [Fact]
+ public void Equals_ShouldReturnFalse_WhenErrorCodesAreDifferent()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code1", "Test description");
+ var error2 = Error.Validation("Test.Code2", "Test description");
+
+ // Act & Assert
+ Assert.NotEqual(error1, error2);
+ }
+
+ [Fact]
+ public void Equals_ShouldReturnFalse_WhenErrorDescriptionsAreDifferent()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code", "Test description 1");
+ var error2 = Error.Validation("Test.Code", "Test description 2");
+
+ // Act & Assert
+ Assert.NotEqual(error1, error2);
+ }
+
+ [Fact]
+ public void Equals_ShouldReturnFalse_WhenErrorTypesAreDifferent()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code", "Test description");
+ var error2 = Error.NotFound("Test.Code", "Test description");
+
+ // Act & Assert
+ Assert.NotEqual(error1, error2);
+ }
+
+ [Fact]
+ public void GetHashCode_ShouldReturnSameValue_WhenErrorsAreEqual()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code", "Test description");
+ var error2 = Error.Validation("Test.Code", "Test description");
+
+ // Act
+ var hashCode1 = error1.GetHashCode();
+ var hashCode2 = error2.GetHashCode();
+
+ // Assert
+ Assert.Equal(hashCode1, hashCode2);
+ }
+
+ [Fact]
+ public void GetHashCode_ShouldReturnDifferentValues_WhenErrorsAreDifferent()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Code1", "Test description");
+ var error2 = Error.Validation("Test.Code2", "Test description");
+
+ // Act
+ var hashCode1 = error1.GetHashCode();
+ var hashCode2 = error2.GetHashCode();
+
+ // Assert
+ Assert.NotEqual(hashCode1, hashCode2);
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/Mews.ExchangeRateMonitor.Common.Tests.Unit.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/Mews.ExchangeRateMonitor.Common.Tests.Unit.csproj
new file mode 100644
index 000000000..2291ba74f
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/Mews.ExchangeRateMonitor.Common.Tests.Unit.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net9.0
+ enable
+ enable
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultImplicitConversionTests.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultImplicitConversionTests.cs
new file mode 100644
index 000000000..a036675b3
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultImplicitConversionTests.cs
@@ -0,0 +1,70 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+namespace Mews.ExchangeRateMonitor.Common.Tests.Unit;
+
+public class ResultImplicitConversionTests
+{
+ [Fact]
+ public void ImplicitConversion_ShouldCreateSuccessResult_FromValue()
+ {
+ // Arrange
+ const int value = 42;
+
+ // Act
+ Result result = value;
+
+ // Assert
+ Assert.True(result.IsSuccess);
+ Assert.Equal(value, result.Value);
+ }
+
+ [Fact]
+ public void ImplicitConversion_ShouldCreateErrorResult_FromError()
+ {
+ // Arrange
+ var error = Error.Validation("Test.Error", "Test error description");
+
+ // Act
+ Result result = error;
+
+ // Assert
+ Assert.True(result.IsError);
+ Assert.Equal(error, result.FirstError);
+ }
+
+ [Fact]
+ public void ImplicitConversion_ShouldCreateErrorResult_FromErrorList()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Error1", "Test error description 1");
+ var error2 = Error.Validation("Test.Error2", "Test error description 2");
+ var errors = new List { error1, error2 };
+
+ // Act
+ Result result = errors;
+
+ // Assert
+ Assert.True(result.IsError);
+ Assert.Equal(2, result.Errors.Count);
+ Assert.Equal(error1, result.FirstError);
+ }
+
+ [Fact]
+ public void ImplicitConversion_ShouldCreateErrorResult_FromErrorArray()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Error1", "Test error description 1");
+ var error2 = Error.Validation("Test.Error2", "Test error description 2");
+ var errors = new[] { error1, error2 };
+
+ // Act
+ Result result = errors;
+
+ // Assert
+ Assert.True(result.IsError);
+ Assert.Equal(2, result.Errors.Count);
+ Assert.Equal(error1, result.FirstError);
+ Assert.Contains(error1, result.Errors);
+ Assert.Contains(error2, result.Errors);
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultTests.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultTests.cs
new file mode 100644
index 000000000..7c2dd89bd
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.Common.Tests.Unit/ResultTests.cs
@@ -0,0 +1,128 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+
+namespace Mews.ExchangeRateMonitor.Common.Tests.Unit;
+
+public class ResultTests
+{
+ [Fact]
+ public void Success_ShouldReturnSuccessInstance()
+ {
+ // Act
+ var success = Result.Success;
+
+ // Assert
+ Assert.IsType(success);
+ }
+
+ [Fact]
+ public void Result_ShouldImplicitlyConvertValueToResult()
+ {
+ // Arrange
+ const string value = "test value";
+
+ // Act
+ Result result = value;
+
+ // Assert
+ Assert.True(result.IsSuccess);
+ Assert.False(result.IsError);
+ Assert.Equal(value, result.Value);
+ Assert.Empty(result.Errors);
+ }
+
+ [Fact]
+ public void Result_ShouldImplicitlyConvertErrorToResult()
+ {
+ // Arrange
+ var error = Error.Validation("Test.Error", "Test error description");
+
+ // Act
+ Result result = error;
+
+ // Assert
+ Assert.False(result.IsSuccess);
+ Assert.True(result.IsError);
+ Assert.Equal(error, result.FirstError);
+ Assert.Single(result.Errors);
+ Assert.Contains(error, result.Errors);
+ }
+
+ [Fact]
+ public void Result_ShouldImplicitlyConvertErrorListToResult()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Error1", "Test error description 1");
+ var error2 = Error.Validation("Test.Error2", "Test error description 2");
+ var errors = new List { error1, error2 };
+
+ // Act
+ Result result = errors;
+
+ // Assert
+ Assert.False(result.IsSuccess);
+ Assert.True(result.IsError);
+ Assert.Equal(error1, result.FirstError);
+ Assert.Equal(2, result.Errors.Count);
+ Assert.Contains(error1, result.Errors);
+ Assert.Contains(error2, result.Errors);
+ }
+
+ [Fact]
+ public void Result_ShouldImplicitlyConvertErrorArrayToResult()
+ {
+ // Arrange
+ var error1 = Error.Validation("Test.Error1", "Test error description 1");
+ var error2 = Error.Validation("Test.Error2", "Test error description 2");
+ var errors = new[] { error1, error2 };
+
+ // Act
+ Result result = errors;
+
+ // Assert
+ Assert.False(result.IsSuccess);
+ Assert.True(result.IsError);
+ Assert.Equal(error1, result.FirstError);
+ Assert.Equal(2, result.Errors.Count);
+ Assert.Contains(error1, result.Errors);
+ Assert.Contains(error2, result.Errors);
+ }
+
+ [Fact]
+ public void Result_ShouldThrowArgumentNullException_WhenValueIsNull()
+ {
+ // Arrange
+ string? nullValue = null;
+
+ // Act & Assert
+ Assert.Throws(() =>
+ {
+ Result result = nullValue!;
+ });
+ }
+
+ [Fact]
+ public void Result_ShouldThrowArgumentNullException_WhenErrorListIsNull()
+ {
+ // Arrange
+ List? nullErrors = null;
+
+ // Act & Assert
+ Assert.Throws(() =>
+ {
+ Result result = nullErrors!;
+ });
+ }
+
+ [Fact]
+ public void Result_ShouldThrowArgumentException_WhenErrorListIsEmpty()
+ {
+ // Arrange
+ var emptyErrors = new List();
+
+ // Act & Assert
+ Assert.Throws(() =>
+ {
+ Result result = emptyErrors;
+ });
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Currency.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Currency.cs
new file mode 100644
index 000000000..26b860de2
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Currency.cs
@@ -0,0 +1,19 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Domain;
+
+public class Currency
+{
+ public Currency(string code)
+ {
+ Code = code;
+ }
+
+ ///
+ /// Three-letter ISO 4217 code of the currency.
+ ///
+ public string Code { get; }
+
+ public override string ToString()
+ {
+ return Code;
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/CurrencyExchangeRate.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/CurrencyExchangeRate.cs
new file mode 100644
index 000000000..0c3af6cc6
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/CurrencyExchangeRate.cs
@@ -0,0 +1,25 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Domain;
+
+public class CurrencyExchangeRate
+{
+ public CurrencyExchangeRate(
+ Currency sourceCurrency,
+ Currency targetCurrency,
+ decimal sourceCurrencyAmount,
+ decimal targetCurrencyRate)
+ {
+ SourceCurrency = sourceCurrency;
+ TargetCurrency = targetCurrency;
+ SourceCurrencyAmount = sourceCurrencyAmount;
+ TargetCurrencyRate = targetCurrencyRate;
+ }
+
+ public Currency SourceCurrency { get; }
+ public decimal SourceCurrencyAmount { get; }
+
+ public Currency TargetCurrency { get; }
+ public decimal TargetCurrencyRate { get; }
+
+ public override string ToString() =>
+ $"{SourceCurrencyAmount} {SourceCurrency} = {TargetCurrencyRate} {TargetCurrency} ";
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Mews.ExchangeRateMonitor.ExchangeRate.Domain.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Mews.ExchangeRateMonitor.ExchangeRate.Domain.csproj
new file mode 100644
index 000000000..125f4c93b
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Domain/Mews.ExchangeRateMonitor.ExchangeRate.Domain.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/ExchangeRatesModuleRegistration.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/ExchangeRatesModuleRegistration.cs
new file mode 100644
index 000000000..11f645a57
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/ExchangeRatesModuleRegistration.cs
@@ -0,0 +1,75 @@
+using FluentValidation;
+using Mews.ExchangeRateMonitor.Common.API.Extensions;
+using Mews.ExchangeRateMonitor.Common.Application.Extensions;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Features;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.HttpClient;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features;
+
+public static class ExchangeRatesModuleRegistration
+{
+ public static IServiceCollection AddExchangeRatesModule(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddCustomAppOptions(configuration);
+ services.AddHttpClients();
+ services.AddCustomServices();
+ services.AddExchangeRatesModuleApi();
+ return services;
+ }
+
+ private static IServiceCollection AddCustomAppOptions(this IServiceCollection services, IConfiguration configuration)
+ {
+ var msg = $"{nameof(ExchangeRateModuleOptions)} is not configured properly.";
+ services.AddOptions()
+ .Bind(configuration.GetSection(nameof(ExchangeRateModuleOptions)))
+ .ValidateDataAnnotations()
+ .ValidateOnStart()
+ .Validate(x => !string.IsNullOrEmpty(x.CnbExratesOptions.BaseCnbApiUri), $"{msg} Base url shouldn't been empty or null");
+
+ return services;
+ }
+
+ private static IServiceCollection AddCustomServices(this IServiceCollection services)
+ {
+ services.AddScoped();
+ return services;
+ }
+
+ private static IServiceCollection AddHttpClients(this IServiceCollection services)
+ {
+ services.AddHttpClient(HttpClientConsts.HttpCnbClient, (serviceProvider, httpClient) =>
+ {
+ var cnbExrateOptions = serviceProvider
+ .GetRequiredService>().Value.CnbExratesOptions;
+
+ var baseUri = cnbExrateOptions.BaseCnbApiUri.EndsWith("/")
+ ? cnbExrateOptions.BaseCnbApiUri
+ : cnbExrateOptions.BaseCnbApiUri + "/";
+
+ httpClient.BaseAddress = new Uri(cnbExrateOptions.BaseCnbApiUri);
+ })
+ //recycle each individual TCP connection every 5 minutes
+ .ConfigurePrimaryHttpMessageHandler(() =>
+ new SocketsHttpHandler
+ {
+ PooledConnectionLifetime = TimeSpan.FromMinutes(5),
+ })
+ //keep the HttpClient handler alive forever, so its connection pool isn’t thrown away every 2 minutes
+ .SetHandlerLifetime(Timeout.InfiniteTimeSpan);
+
+ return services;
+ }
+
+ private static IServiceCollection AddExchangeRatesModuleApi(this IServiceCollection services)
+ {
+ services.RegisterApiEndpointsFromAssemblyContaining(typeof(ExchangeRatesModuleRegistration));
+ services.RegisterHandlersFromAssemblyContaining(typeof(ExchangeRatesModuleRegistration));
+ services.AddValidatorsFromAssembly(typeof(ExchangeRatesModuleRegistration).Assembly, includeInternalTypes: true);
+
+ return services;
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/ExchangeRateProvider.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/ExchangeRateProvider.cs
new file mode 100644
index 000000000..babc20427
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/ExchangeRateProvider.cs
@@ -0,0 +1,81 @@
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+using Mews.ExchangeRateMonitor.ExchangeRate.Domain;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.HttpClient;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using System.Net.Http.Json;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features;
+
+public interface IExchangeRateProvider
+{
+ Task>> GetDailyRatesAsync(DateOnly date, CancellationToken ct);
+}
+
+public sealed class ExchangeRateProvider(
+ ILogger logger,
+ IOptions opts,
+ IMemoryCache cache,
+ IHttpClientFactory httpClientFactory) : IExchangeRateProvider
+{
+ private const string TargetCurrencyCode = "CZK";
+ private static string CnbDailyKey(DateOnly d) => $"cnb:daily:{d:yyyy-MM-dd}";
+
+ public async Task>> GetDailyRatesAsync(DateOnly date, CancellationToken ct)
+ {
+ var key = CnbDailyKey(date);
+ if (cache.TryGetValue>(key, out var cached) && cached is not null)
+ return cached;
+
+ var client = httpClientFactory.CreateClient(HttpClientConsts.HttpCnbClient);
+ var url = $"exrates/daily?date={date:yyyy-MM-dd}";
+
+ try
+ {
+ var cnbDailyRates = await client.GetFromJsonAsync(url, ct);
+ if (cnbDailyRates?.Rates is null)
+ {
+ var msg = $"CNB response was null or missing 'rates' for ${url}";
+ logger.LogWarning(msg);
+ return Error.Failure($"{nameof(GetDailyRatesAsync)}", msg);
+ }
+
+ var reqCurr = opts.Value.CnbExratesOptions.RequiredCurrencies.ToHashSet();
+ var filteredRates = cnbDailyRates.Rates
+ .Where(cnbRate => reqCurr.Any(c => c == cnbRate.CurrencyCode))
+ .Select(x => x.ToCurrencyExchangeRate(TargetCurrencyCode))
+ .ToList();
+
+ cache.Set(key, filteredRates, BuildCacheOptions(date, key));
+
+ return filteredRates;
+ }
+ catch (HttpRequestException ex)
+ {
+ var msg = $"HTTP error calling CNB for {url}";
+ logger.LogError(ex, msg);
+ return Error.Failure(nameof(GetDailyRatesAsync), msg);
+ }
+ catch (Exception ex)
+ {
+ var msg = $"Unexpected error calling CNB for {url}";
+ logger.LogError(ex, msg);
+ return Error.Failure(nameof(GetDailyRatesAsync), msg);
+ }
+ }
+
+
+ private MemoryCacheEntryOptions BuildCacheOptions(DateOnly date, string key) =>
+ new MemoryCacheEntryOptions
+ {
+ AbsoluteExpirationRelativeToNow = date < DateOnly.FromDateTime(DateTime.UtcNow)
+ ? TimeSpan.FromDays(30) // historical = long TTL
+ : TimeSpan.FromMinutes(10) // today = short TTL
+ }
+ .SetSize(1)
+ .RegisterPostEvictionCallback((_, _, reason, _) =>
+ logger.LogDebug($"Cache evicted {key} due to {reason}"));
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Contracts.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Contracts.cs
new file mode 100644
index 000000000..8a7afdb2e
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Contracts.cs
@@ -0,0 +1,5 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public sealed record GetExratesDailyRequest(DateOnly Date);
+public sealed record GetExratesDailyResponse(IEnumerable Rates);
+public sealed record CurrencyExchangeRateDto(string SourceCurrency, string TargetCurrency, decimal Amount, decimal Rate);
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Endpoint.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Endpoint.cs
new file mode 100644
index 000000000..e0e2a78f1
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Endpoint.cs
@@ -0,0 +1,31 @@
+using Mews.ExchangeRateMonitor.Common.API.Abstractions;
+using Mews.ExchangeRateMonitor.Common.API.Extensions;
+using Mews.ExchangeRateMonitor.Common.API.RateLimiting;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.Routes;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public class GetExratesDailyEndpoint : IApiEndpoint
+{
+ public void MapEndpoint(WebApplication app)
+ {
+ app.MapGet(RouteConsts.ExratesDailyRoute, Handle)
+ .WithDescription($"Returns last valid data for selected day")
+ .RequireRateLimiting(AppRateLimiting.GlobalRateLimitPolicy);
+ }
+
+ private static async Task Handle(
+ [AsParameters] GetExratesDailyRequest request,
+ [FromServices] IGetExratesDailyHandler handler,
+ CancellationToken cancellationToken)
+ {
+ var response = await handler.HandleAsync(request, cancellationToken);
+ if (response.IsError)
+ return response.Errors.ToProblem();
+
+ return Results.Ok(response.Value);
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.ExternalContracts.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.ExternalContracts.cs
new file mode 100644
index 000000000..0e2fe6cd2
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.ExternalContracts.cs
@@ -0,0 +1,12 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public sealed record CnbApiDailyRatesResponseDto(IEnumerable Rates);
+public sealed record CnbApiDailyRateDto(
+ decimal Amount,
+ string Country,
+ string Currency,
+ string CurrencyCode,
+ int Order,
+ decimal Rate,
+ DateTime ValidFor);
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Handler.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Handler.cs
new file mode 100644
index 000000000..ec2c98f36
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Handler.cs
@@ -0,0 +1,38 @@
+using FluentValidation;
+using Mews.ExchangeRateMonitor.Common.Application.Extensions;
+using Mews.ExchangeRateMonitor.Common.Domain.Handlers;
+using Mews.ExchangeRateMonitor.Common.Domain.Results;
+using Microsoft.Extensions.Logging;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public interface IGetExratesDailyHandler : IHandler
+{
+ Task>> HandleAsync(GetExratesDailyRequest request, CancellationToken ct);
+}
+
+public sealed class GetExratesDailyHandler(
+ ILogger logger,
+ IExchangeRateProvider exchangeRateProvider,
+ IValidator validator) : IGetExratesDailyHandler
+{
+ public async Task>> HandleAsync(GetExratesDailyRequest request, CancellationToken ct)
+ {
+ logger.LogInformation($"{nameof(GetExratesDailyHandler)}.{nameof(HandleAsync)} started");
+
+ var validationResult = await validator.ValidateAsync(request, ct);
+ if (!validationResult.IsValid)
+ return validationResult.ToDomainErrors(nameof(GetExratesDailyRequest));
+
+ var dailyRatesRes = await exchangeRateProvider.GetDailyRatesAsync(request.Date, ct);
+ if (dailyRatesRes.IsError)
+ return dailyRatesRes.Errors;
+
+ var dailyRates = dailyRatesRes.Value ?? [];
+ var rateDtos = dailyRates.Select(x => x.ToRateDto()).ToList();
+
+ logger.LogInformation($"{nameof(GetExratesDailyHandler)}.{nameof(HandleAsync)} is successfull");
+
+ return rateDtos;
+ }
+}
\ No newline at end of file
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Mappings.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Mappings.cs
new file mode 100644
index 000000000..6f48c151b
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Mappings.cs
@@ -0,0 +1,13 @@
+using Mews.ExchangeRateMonitor.ExchangeRate.Domain;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public static class GetExratesDailyMappings
+{
+ public static CurrencyExchangeRate ToCurrencyExchangeRate(this CnbApiDailyRateDto cnbRate, string targerCurrency) =>
+ new CurrencyExchangeRate(new(cnbRate.CurrencyCode), new(targerCurrency), cnbRate.Amount, cnbRate.Rate);
+
+ public static CurrencyExchangeRateDto ToRateDto(this CurrencyExchangeRate rate) =>
+ new(rate.SourceCurrency.Code, rate.TargetCurrency.Code, rate.SourceCurrencyAmount, rate.TargetCurrencyRate);
+}
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Validators.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Validators.cs
new file mode 100644
index 000000000..bf40e6ef5
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Features/GetExratesDaily/GetExratesDaily.Validators.cs
@@ -0,0 +1,16 @@
+using FluentValidation;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+using Microsoft.Extensions.Options;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Features.GetExratesDaily;
+
+public class GetExratesDailyRequestValidator : AbstractValidator
+{
+ public GetExratesDailyRequestValidator(IOptions opts)
+ {
+ RuleFor(req => req.Date)
+ .NotNull().WithMessage("Date is required.")
+ .LessThanOrEqualTo(DateOnly.FromDateTime(DateTime.UtcNow))
+ .WithMessage("Date cannot be in the future.");
+ }
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Mews.ExchangeRateMonitor.ExchangeRate.Features.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Mews.ExchangeRateMonitor.ExchangeRate.Features.csproj
new file mode 100644
index 000000000..75bf1a9d0
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Mews.ExchangeRateMonitor.ExchangeRate.Features.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/CnbExratesOptions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/CnbExratesOptions.cs
new file mode 100644
index 000000000..05889bcd7
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/CnbExratesOptions.cs
@@ -0,0 +1,7 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+
+public sealed record CnbExratesOptions
+{
+ public string BaseCnbApiUri { get; init; } = null!;
+ public IEnumerable RequiredCurrencies { get; set; } = [];
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/ExchangeRateModuleOptions.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/ExchangeRateModuleOptions.cs
new file mode 100644
index 000000000..2663ca15b
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Options/ExchangeRateModuleOptions.cs
@@ -0,0 +1,6 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+
+public sealed record ExchangeRateModuleOptions
+{
+ public CnbExratesOptions CnbExratesOptions { get; init; } = new();
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/HttpClient/HttpClientConsts.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/HttpClient/HttpClientConsts.cs
new file mode 100644
index 000000000..0206196d0
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/HttpClient/HttpClientConsts.cs
@@ -0,0 +1,6 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.HttpClient;
+
+public static class HttpClientConsts
+{
+ public const string HttpCnbClient = "CnbClient";
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/Routes/RouteConsts.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/Routes/RouteConsts.cs
new file mode 100644
index 000000000..c34471727
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Features/Shared/Routes/RouteConsts.cs
@@ -0,0 +1,8 @@
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.Routes;
+
+public static class RouteConsts
+{
+ public const string BaseRoute = "/api/exrates";
+ public const string GetTestItem = $"{BaseRoute}/gettestitem";
+ public const string ExratesDailyRoute = $"{BaseRoute}/daily";
+}
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure.csproj b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure.csproj
new file mode 100644
index 000000000..954beb6a8
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure/Mews.ExchangeRateMonitor.ExchangeRate.Infrastructure.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Tests.Unit/Features/ExchangeRateProviderTests.cs b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Tests.Unit/Features/ExchangeRateProviderTests.cs
new file mode 100644
index 000000000..a4aea4b7e
--- /dev/null
+++ b/jobs/Backend/Task/Mews.ExchangeRateMonitor.ExchangeRate.Tests.Unit/Features/ExchangeRateProviderTests.cs
@@ -0,0 +1,109 @@
+using FluentAssertions;
+using Mews.ExchangeRateMonitor.ExchangeRate.Domain;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Features;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Options;
+using Mews.ExchangeRateMonitor.ExchangeRate.Features.Shared.HttpClient;
+using Mews.ExchangeRateMonitor.ExchangeRate.Tests.Unit.TestHelpers;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using NSubstitute;
+using System.Net;
+
+namespace Mews.ExchangeRateMonitor.ExchangeRate.Tests.Unit.Features;
+
+public class ExchangeRateProviderTests
+{
+ private readonly IEnumerable _requiredCurrencies = ["USD", "EUR"];
+ private (int CurAmount, string Json) ReturnedJsonWithCurAmount => (3, """
+ {"rates":[
+ {"currencyCode":"USD","amount":1,"rate":22.00},
+ {"currencyCode":"EUR","amount":1,"rate":25.00},
+ {"currencyCode":"PLN","amount":1,"rate":5.00}
+ ]}
+ """);
+
+ private readonly DateOnly _date1 = new DateOnly(2024, 12, 24);
+
+ private static IOptions Opts(IEnumerable reqCurs) =>
+ Options.Create(
+ new ExchangeRateModuleOptions
+ {
+ CnbExratesOptions = new CnbExratesOptions()
+ {
+ BaseCnbApiUri = "https://cnb.local/",
+ RequiredCurrencies = reqCurs
+ }
+ });
+
+ private static IHttpClientFactory HttpFactory(HttpMessageHandler handler)
+ {
+ var client = new HttpClient(handler) { BaseAddress = new Uri("https://cnb.local/") };
+ var f = Substitute.For();
+ f.CreateClient(HttpClientConsts.HttpCnbClient).Returns(client);
+ return f;
+ }
+
+ [Fact]
+ public async Task Returns_Value_From_HttpClient_When_There_Is_No_Chache()
+ {
+ var handler = new StaticResponseHandler(
+ new HttpResponseMessage(HttpStatusCode.OK)
+ {
+ Content = new StringContent(ReturnedJsonWithCurAmount.Json, System.Text.Encoding.UTF8, "application/json")
+ });
+
+ var cache = Substitute.For();
+ var logger = Substitute.For>();
+ var exchangeRateProvider = new ExchangeRateProvider(logger, Opts(_requiredCurrencies), cache, HttpFactory(handler));
+
+ var res = await exchangeRateProvider.GetDailyRatesAsync(_date1, default);
+
+ res.IsError.Should().BeFalse();
+ res.Value!.Count().Should().Be(_requiredCurrencies.Count());
+ }
+
+ [Fact]
+ public async Task Returns_Cached_Value_And_Skips_Http_On_Cache_Hit()
+ {
+ var key = $"cnb:daily:{_date1:yyyy-MM-dd}";
+ var cached = new List { new(new("CNY"), new("CZK"), 1m, 3.334m) };
+
+ var cache = Substitute.For();
+ object boxed = cached;
+ cache.TryGetValue(key, out Arg.Any