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

Prueba tecnica Abel Fincias #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Documentacion/DdC.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentacion/Decisiones de diseno.docx
Binary file not shown.
2 changes: 2 additions & 0 deletions Documentacion/Estimacion
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Después de revisar la tarea, calculo un esfuerzo de 10H, incluída la que he tardado en analizar la solución y plantear el diseño.
Se podrá realizar en el plazo de los 3 días propuestos, no obstante, si se completa antes, se avisará
Binary file added Documentacion/User Stories.ods
Binary file not shown.
82 changes: 82 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/Controllers/MarketPartyController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using eSett.Model;
using Microsoft.AspNetCore.Mvc;

using System.Net;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace MarketPartyAPI.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MarketPartyController : ControllerBase
{
[ActionName("ImportRetailer")]
[HttpGet]
public HttpStatusCode ImportRetailer()
{
if (eSett.Manager.RetailerMg.RMg.Import())
return HttpStatusCode.OK;
else
return HttpStatusCode.InternalServerError;
}
[ActionName("GetRetailer")]
[HttpGet("{id}")]
public Retailer? GetRetailer(int id)
{
return eSett.Manager.RetailerMg.RMg.Get(id) ?? new Retailer() { Code = HttpStatusCode.NoContent.ToString() };
}


[ActionName("ImportDistributionSystemOperator")]
[HttpGet]
public HttpStatusCode ImportDSO()
{
if (eSett.Manager.DistributionSystemOperatorMg.DSOMg.Import())
return HttpStatusCode.OK;
else
return HttpStatusCode.InternalServerError;
}
[ActionName("GetDistributionSystemOperator")]
[HttpGet("{id}")]
public DistributionSystemOperator? GetDSO(int id)
{
return eSett.Manager.DistributionSystemOperatorMg.DSOMg.Get(id) ?? new DistributionSystemOperator() { Code = HttpStatusCode.NoContent.ToString() };
}


[ActionName("ImportBalanceServiceProvider")]
[HttpGet]
public HttpStatusCode ImportBSP()
{
if (eSett.Manager.BalanceServiceProviderMg.BSPMg.Import())
return HttpStatusCode.OK;
else
return HttpStatusCode.InternalServerError;
}
[ActionName("GetBalanceServiceProvider")]
[HttpGet("{id}")]
public BalanceServiceProvider? GetBSP(int id)
{
return eSett.Manager.BalanceServiceProviderMg.BSPMg.Get(id) ?? new BalanceServiceProvider() { Code = HttpStatusCode.NoContent.ToString() };
}


[ActionName("ImportBalanceResponsibleParty")]
[HttpGet]
public HttpStatusCode ImportBRP()
{
if (eSett.Manager.BalanceResponsiblePartyMg.BRPMg.Import())
return HttpStatusCode.OK;
else
return HttpStatusCode.InternalServerError;
}
[ActionName("GetBalanceResponsibleParty")]
[HttpGet("{id}")]
public BalanceResponsibleParty? GetBRP(int id)
{
return eSett.Manager.BalanceResponsiblePartyMg.BRPMg.Get(id) ?? new BalanceResponsibleParty() { Code = HttpStatusCode.NoContent.ToString() };
}

}
}
27 changes: 27 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/MarketPartyAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.18.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\eSett.Manager\eSett.Manager.csproj" />
<ProjectReference Include="..\eSett.Model\eSett.Model.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/MarketPartyAPI.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>
31 changes: 31 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using eSett.Model;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var configuration = new ConfigurationBuilder().AddJsonFile(Environment.CurrentDirectory + "/appsettings.json").Build();

eSett.Manager.MarketPartyMg.Start(configuration.GetSection("APIBaseUrl").Value);
xLog.CreateLog(@"C:\Borrar\");

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
8 changes: 8 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
13 changes: 13 additions & 0 deletions MarketPartyAPI/MarketPartyAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"SqlServerConnection": "Persist Security Info=False;Server=#ServerIP#:#Port#;User ID=*****;Password=*****;Initial Catalog=ESett;"
},
"APIBaseUrl": "https://api.opendata.esett.com/"
}
1 change: 1 addition & 0 deletions MarketPartyAPI/TestAPI/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
26 changes: 26 additions & 0 deletions MarketPartyAPI/TestAPI/TestAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\eSett.API\eSett.API.csproj" />
<ProjectReference Include="..\eSett.Data\eSett.Data.csproj" />
<ProjectReference Include="..\eSett.Manager\eSett.Manager.csproj" />
<ProjectReference Include="..\eSett.Model\eSett.Model.csproj" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions MarketPartyAPI/TestAPI/TestManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using eSett.Manager;

namespace TestAPI
{
[TestClass]
public class TestManager
{
string uri = "https://api.opendata.esett.com/";

[TestMethod]
public void TestImport()
{
MarketPartyMg.Start(uri);

Assert.IsTrue(RetailerMg.RMg.Import(), "No se recuperaron los retailers");

Assert.IsTrue(DistributionSystemOperatorMg.DSOMg.Import(), "No se recuperaron los DSO");

Assert.IsTrue(BalanceResponsiblePartyMg.BRPMg.Import(), "Fallaron los BRP");

Assert.IsTrue(BalanceServiceProviderMg.BSPMg.Import(), "No se importaron los BalanceService");
}

[TestMethod]
public void TestRead()
{

}
}
}
31 changes: 31 additions & 0 deletions MarketPartyAPI/TestAPI/TesteSettAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using eSett.API;

namespace TestAPI
{
[TestClass]
public class TesteSettAPI
{
[TestMethod]
public void TestRetailers()
{
I_APIeSettMg APIMg = new RetailerMg();

Assert.IsNotNull(APIMg, "Es null");

Assert.IsTrue(APIMg.Open("https://api.opendata.esett.com/"), "No se ha iniciado");

var result = APIMg.Get("", "ES", "");

//Assert.IsTrue(result.IsCompletedSuccessfully);

Assert.IsTrue(result.Count == 0, "No es cero");

var result2 = APIMg.Get("", "FI", "");

Assert.IsTrue(result2.Count > 0, "Es cero");

Assert.IsInstanceOfType(result2.First(), new RetailerDTO().GetType(), "No es del mismo tipo");

}
}
}
38 changes: 38 additions & 0 deletions MarketPartyAPI/eSett.API/BalanceResponsiblePartyMg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using eSett.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace eSett.API
{
public class BalanceResponsiblePartyMg : eSettAPIMg, I_APIeSettMg
{
/// <summary>
/// Retrieves a list of BalanceResponsibleParties from eSett API
/// </summary>
/// <param name="code">filter by bspCode</param>
/// <param name="country">filter by bspCountry</param>
/// <param name="name">filter by bspName</param>
/// <returns>List of I_MarketParty</returns>
public List<I_MarketParty> Get(string? code = "", string? country = "", string? name = "")
{
return base.Get<BalanceResponsiblePartyDTO>(_api.BalanceResponsiblePartiesAsync(code, country, name), Fill);
}

I_MarketParty Fill(BalanceResponsiblePartyDTO item)
{
return new BalanceResponsibleParty()
{
Code = item.BrpCode,
Name = item.BrpName,
country = item.Country,
codingScheme = item.CodingScheme,
bussinesId = item.BusinessId,
validityEnd = item.ValidityEnd,
validityStart = item.ValidityStart
};
}
}
}
31 changes: 31 additions & 0 deletions MarketPartyAPI/eSett.API/BalanceServiceProviderMg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using eSett.Model;

namespace eSett.API
{
public class BalanceServiceProviderMg : eSettAPIMg, I_APIeSettMg
{
/// <summary>
/// Retrieves a list of BalanceServiceProviders from eSett API
/// </summary>
/// <param name="code">filter by bspCode</param>
/// <param name="country">filter by bspCountry</param>
/// <param name="name">filter by bspName</param>
/// <returns>List of I_MarketParty</returns>
public List<I_MarketParty> Get(string? code = "", string? country = "", string? name = "")
{
return base.Get<BalanceServiceProviderDTO>(_api.BalanceServiceProvidersAsync(code, country, name), Fill);
}

I_MarketParty Fill(BalanceServiceProviderDTO item)
{
return new BalanceServiceProvider()
{
Code = item.BspCode,
Name = item.BspName,
country = item.Country,
codingScheme = item.CodingScheme,
bussinesId = item.BusinessId
};
}
}
}
30 changes: 30 additions & 0 deletions MarketPartyAPI/eSett.API/DistributionSystemOperatorMg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using eSett.Model;

namespace eSett.API
{
public class DistributionSystemOperatorMg : eSettAPIMg, I_APIeSettMg
{
/// <summary>
/// Retrieves a list of DistributionSystemOperators from eSett API
/// </summary>
/// <param name="code">filter by bspCode</param>
/// <param name="country">filter by bspCountry</param>
/// <param name="name">filter by bspName</param>
/// <returns>List of I_MarketParty</returns>
public List<I_MarketParty> Get(string? code = "", string? country = "", string? name = "")
{
return base.Get<DistributionSystemOperatorDTO>(_api.DistributionSystemOperatorsAsync(code, country, name), Fill);
}

I_MarketParty Fill(DistributionSystemOperatorDTO item)
{
return new DistributionSystemOperator()
{
Code = item.DsoCode,
Name = item.DsoName,
country = item.Country,
codingScheme = item.CodingScheme
};
}
}
}
12 changes: 12 additions & 0 deletions MarketPartyAPI/eSett.API/I_APIeSettMg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using eSett.Model;

namespace eSett.API
{
public interface I_APIeSettMg
{
bool Open(string uri);

List<I_MarketParty> Get(string? code = "", string? country = "", string? name = "");

}
}
1 change: 1 addition & 0 deletions MarketPartyAPI/eSett.API/OpenAPIs/openapi.json

Large diffs are not rendered by default.

Loading