-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22cf314
commit 3c802e4
Showing
14 changed files
with
253 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using VirtualMind.Application.Interfaces; | ||
using VirtuaMind.Infrastructure.RestServices.ExternalServices; | ||
|
||
namespace VirtuaMind.Infrastructure.DI | ||
{ | ||
public static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddInfrastructure(this IServiceCollection services) | ||
{ | ||
services.AddScoped<IBancoProvinciaRestService, BancoProvinciaService>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
VirtuaMind.Infrastructure/FunctionalServices/MonetaryConversions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace VirtuaMind.Infrastructure.FunctionalServices | ||
{ | ||
public static class MonetaryConversions | ||
{ | ||
public static string ConvertUSDToBRL(this string value) | ||
{ | ||
decimal resultCast; | ||
decimal.TryParse(value, out resultCast); | ||
|
||
var conversionResult = resultCast / 4; | ||
|
||
return conversionResult.ToString(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
VirtuaMind.Infrastructure/RestServices/ExternalServices/BancoProvinciaService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using VirtualMind.Application.Interfaces; | ||
using VirtuaMind.Infrastructure.FunctionalServices; | ||
using VirtuaMind.Infrastructure.RestServices.Template; | ||
|
||
namespace VirtuaMind.Infrastructure.RestServices.ExternalServices | ||
{ | ||
public class BancoProvinciaService : RestService, IBancoProvinciaRestService | ||
{ | ||
private readonly string BASEURL = "https://www.bancoprovincia.com.ar"; | ||
|
||
public BancoProvinciaService() | ||
{ | ||
SetClientRequest(BASEURL); | ||
} | ||
|
||
public async Task<List<string>> GetUSDExchangeRate() | ||
{ | ||
var result = await Execute(null, "Principal/Dolar", RestSharp.Method.GET); | ||
|
||
var content = JsonConvert.DeserializeObject<List<string>>(result); | ||
|
||
return content; | ||
} | ||
|
||
public async Task<List<string>> GetBRLExchangeRate() | ||
{ | ||
var content = await GetUSDExchangeRate(); | ||
|
||
var convertedList = new List<string>() | ||
{ | ||
content[0].ConvertUSDToBRL(), | ||
content[1].ConvertUSDToBRL(), | ||
content[2] | ||
}; | ||
|
||
return convertedList; | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
VirtuaMind.Infrastructure/RestServices/Template/RestService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using RestSharp; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtuaMind.Infrastructure.RestServices.Template | ||
{ | ||
public abstract class RestService | ||
{ | ||
private RestClient BaseClient; | ||
private RestRequest Request; | ||
private dynamic Response; | ||
|
||
public RestService() | ||
{ | ||
BaseClient = new RestClient(); | ||
Request = new RestRequest(); | ||
} | ||
|
||
protected async Task<dynamic> Execute(Dictionary<string, object> keyValueParameters, string requestUri, Method method) | ||
{ | ||
InitializeParametersRequest(requestUri, method, keyValueParameters); | ||
|
||
await SendRequestAsync(); | ||
|
||
return Response.Content; | ||
} | ||
|
||
protected void SetClientRequest(string baseURL) | ||
{ | ||
BaseClient = new RestClient(baseURL); | ||
} | ||
|
||
private void InitializeParametersRequest(string requestUri, | ||
Method method, | ||
Dictionary<string, object> keyValueParameters) | ||
{ | ||
SetResource(requestUri); | ||
SetHttpMethod(method); | ||
AddParameters(keyValueParameters); | ||
} | ||
|
||
private void SetResource(string requestUri) | ||
{ | ||
Request.Resource = requestUri; | ||
} | ||
|
||
private void SetHttpMethod(Method method) | ||
{ | ||
Request.Method = method; | ||
} | ||
|
||
private void AddParameters(Dictionary<string, object> keyValueParameters) | ||
{ | ||
if (keyValueParameters == null) | ||
return; | ||
|
||
foreach (var (key, value) in keyValueParameters) | ||
{ | ||
Request.AddParameter(key, value); | ||
} | ||
} | ||
|
||
private async Task SendRequestAsync<T>() | ||
{ | ||
Response = await BaseClient.ExecuteAsync<T>(this.Request); | ||
} | ||
|
||
private async Task SendRequestAsync() | ||
{ | ||
Response = await BaseClient.ExecuteAsync(this.Request); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
BaseClient = null; | ||
Request = null; | ||
Response = null; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
VirtuaMind.Infrastructure/VirtuaMind.Infrastructure.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
<PackageReference Include="RestSharp" Version="106.11.7" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\VirtualMind.Application\VirtualMind.Application.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
VirtualMind.Application/Interfaces/IBancoProvinciaService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtualMind.Application.Interfaces | ||
{ | ||
public interface IBancoProvinciaRestService | ||
{ | ||
Task<List<string>> GetUSDExchangeRate(); | ||
|
||
Task<List<string>> GetBRLExchangeRate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using VirtualMind.Application.DTOs; | ||
using VirtualMind.Application.Queries; | ||
|
||
namespace VirtualMind.WebApp.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class ExchangeController : ControllerBase | ||
{ | ||
private readonly ILogger<WeatherForecastController> _logger; | ||
private readonly IMediator _mediator; | ||
|
||
public ExchangeController(ILogger<WeatherForecastController> logger, IMediator mediator) | ||
{ | ||
_logger = logger; | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IEnumerable<ExchangeRateDTO>> GetExchangeRate([FromQuery]GetCurrencyExchange getCurrencyExchange) | ||
{ | ||
var response = await this._mediator.Send(getCurrencyExchange); | ||
|
||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters