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 técnica API. Hernán Ortiz #20

Open
wants to merge 1 commit 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 not shown.
Binary file not shown.
Binary file not shown.
1,026 changes: 1,026 additions & 0 deletions .vs/Prueba_tecnica_net_solucion/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added .vs/Prueba_tecnica_net_solucion/v17/.futdcache.v2
Binary file not shown.
Binary file added .vs/Prueba_tecnica_net_solucion/v17/.suo
Binary file not shown.
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\README.md",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file added .vs/prueba_tecnica_net2/v17/.wsuo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Prueba_tecnica_net.Controllers;

[Route("api/[controller]")]
[ApiController]
public class BalanceResponsiblePartyController : ControllerBase
{
private readonly ApiService _apiService;

public BalanceResponsiblePartyController(ApiService apiService)
{
_apiService = apiService;
}

// Endpoint para consultar y almacenar los datos de la API
[HttpPost("fetch")]
public async Task<IActionResult> FetchAndStoreBalanceResponsibleParties([FromBody] BalanceResponsiblePartyFilter filter)
{
if (filter == null)
{
return BadRequest("Invalid filter parameters.");
}

await _apiService.FetchAndStoreBalanceResponsibleParties(filter.Code, filter.Country, filter.Name);

return Ok("Data fetched and stored successfully.");
}
}
34 changes: 34 additions & 0 deletions Prueba_tecnica_net/Controllers/DBDatosAlmacenadosController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Prueba_tecnica_net.Controllers;

[ApiController]
[Route("api/[controller]")]
public class DBDatosAlmacenadosController : Controller
{
private readonly IBalanceResponsiblePartyRepository _repository;

public DBDatosAlmacenadosController(IBalanceResponsiblePartyRepository repository)
{
_repository = repository;
}

// GET: api/BalanceResponsibleParty
[HttpGet]
public async Task<ActionResult<List<BalanceResponsibleParty>>> GetAll()
{
try
{
var parties = await _repository.GetAllAsync();

if (parties == null || !parties.Any())
{
return NoContent(); // Devuelve 204 si no hay datos
}

return Ok(parties); // Devuelve 200 con los datos
}
catch (Exception ex)
{
return StatusCode(500, $"Error interno: {ex.Message}"); // Devuelve 500 en caso de error
}
}
}
14 changes: 14 additions & 0 deletions Prueba_tecnica_net/Data/ApplicationDbConstext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Prueba_tecnica_net.Models;

namespace Prueba_tecnica_net.Data;

public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}

public DbSet<BalanceResponsibleParty> BalanceResponsibleParties { get; set; }
}
9 changes: 9 additions & 0 deletions Prueba_tecnica_net/Filter/BalanceResponsiblePartyFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Prueba_tecnica_net.Filter
{
public class BalanceResponsiblePartyFilter
{
public string Code { get; set; }
public string Country { get; set; }
public string Name { get; set; }
}
}
10 changes: 10 additions & 0 deletions Prueba_tecnica_net/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global using Prueba_tecnica_net.Controllers;
global using Prueba_tecnica_net.Models;
global using Prueba_tecnica_net.Repositories;
global using Microsoft.AspNetCore.Identity;
global using System.Net.Http;
global using System.Text.Json;
global using System.Threading.Tasks;
global using Prueba_tecnica_net.Filter;
global using Microsoft.AspNetCore.Mvc;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Prueba_tecnica_net/Migrations/20241116170431_PrimeraMigración.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Prueba_tecnica_net.Migrations
{
public partial class PrimeraMigración : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BalanceResponsibleParties",
columns: table => new
{
BrpCode = table.Column<string>(type: "nvarchar(450)", nullable: false),
BrpName = table.Column<string>(type: "nvarchar(max)", nullable: false),
BusinessId = table.Column<string>(type: "nvarchar(max)", nullable: false),
CodingScheme = table.Column<string>(type: "nvarchar(max)", nullable: false),
Country = table.Column<string>(type: "nvarchar(max)", nullable: false),
ValidityEnd = table.Column<string>(type: "nvarchar(max)", nullable: false),
ValidityStart = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BalanceResponsibleParties", x => x.BrpCode);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BalanceResponsibleParties");
}
}
}
60 changes: 60 additions & 0 deletions Prueba_tecnica_net/Migrations/ApplicationDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Prueba_tecnica_net.Data;

#nullable disable

namespace Prueba_tecnica_net.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.36")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

modelBuilder.Entity("Prueba_tecnica_net.Models.BalanceResponsibleParty", b =>
{
b.Property<string>("BrpCode")
.HasColumnType("nvarchar(450)");

b.Property<string>("BrpName")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("BusinessId")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("CodingScheme")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Country")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("ValidityEnd")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("ValidityStart")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("BrpCode");

b.ToTable("BalanceResponsibleParties");
});
#pragma warning restore 612, 618
}
}
}
30 changes: 30 additions & 0 deletions Prueba_tecnica_net/Models/BalanceResponsibleParty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace Prueba_tecnica_net.Models;

public class BalanceResponsibleParty
{
[Key]
[JsonPropertyName("brpCode")]
public string BrpCode { get; set; } // El nombre que tiene la API es "brpCode"

[JsonPropertyName("brpName")]
public string BrpName { get; set; }

[JsonPropertyName("businessId")]
public string BusinessId { get; set; }

[JsonPropertyName("codingScheme")]
public string CodingScheme { get; set; }

[JsonPropertyName("country")]
public string Country { get; set; }

[JsonPropertyName("validityStart")]
public string ValidityStart { get; set; }

[JsonPropertyName("validityEnd")]
public string ValidityEnd { get; set; }
}

40 changes: 40 additions & 0 deletions Prueba_tecnica_net/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Prueba_tecnica_net.Data;

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();
builder.Services.AddHttpClient<ApiService>(client =>
{
client.BaseAddress = new Uri("https://api.opendata.esett.com/"); // Direcci�n base de la API
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
builder.Services.AddScoped<IBalanceResponsiblePartyRepository,BalanceResponsiblePartyRepository>();


//A�adimos los servicios de la base de datos
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));

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();
31 changes: 31 additions & 0 deletions Prueba_tecnica_net/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64131",
"sslPort": 44329
}
},
"profiles": {
"Prueba_tecnica_net": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7037;http://localhost:5228",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
21 changes: 21 additions & 0 deletions Prueba_tecnica_net/Prueba_tecnica_net.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.36">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="6.0.11" />
</ItemGroup>

</Project>
Loading