Cambio de nombre a API

This commit is contained in:
2026-03-05 09:22:21 +01:00
parent e55dd0ef68
commit c795be9cd5
11 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="7.5.2" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.14.28" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="tsUtilidades" Version="1.1.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SanchoToro\bdGrupoSanchoToro\bdGrupoSanchoToro.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@ApiExcelGuadex_HostAddress = http://localhost:5188
GET {{ApiExcelGuadex_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,88 @@
using ApiDatosGuadex.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Data.Common;
using bdGrupoSanchoToro.dbcontext;
using bdGrupoSanchoToro;
namespace ApiDatosGuadex.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class HomeController : Controller
{
//metodo
[HttpGet("lee")]
public IActionResult LeeSQL(string bd, string sqlh)
{
// bdGestionGuadex.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Otros, "Inicio Log",null);
Response.ContentType = "text/plain";
try
{
DbConnection? db = null;
switch (bd.ToLower())
{
case "sanchotoro":
{
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
break;
}
//case "guadex":
// {
// db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
// break;
// }
}
// string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
string res = tsUtilidades.bbdd.LeeMysql(db, sqlh);
// termiancion en CRLF
res = res.Replace("\n", "\r\n");
return Content(res, "text/plain", System.Text.Encoding.UTF8);
}
catch (Exception ex)
{
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en LeeSQL", ex.Message, ex);
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
}
}
public IActionResult EjeSQL(string bd, string sqlh)
{
Response.ContentType = "text/plain";
try
{
DbConnection? db = null;
switch (bd.ToLower())
{
case "sanchotoro":
{
db = tscGrupoSanchoToro.NuevoContexto().Database.GetDbConnection();
break;
}
//case "guadex":
// {
// db = bdGuadex.tscGuadex.NuevoContexto().Database.GetDbConnection();
// break;
// }
}
string res = tsUtilidades.bbdd.EjeMySqlHex(db, sqlh);
// terminacion en CRLF
res = res.Replace("\n", "\r\n");
return Content(res, "text/plain", System.Text.Encoding.UTF8);
}
catch (Exception ex)
{
bdGrupoSanchoToro.db.Utilidades.AñadeLog(tsUtilidades.Enumeraciones.TipoLog.Fallo, "Error en EjeSQL", ex.Message, ex);
return Content($"Error: {ex.Message}\r\n", "text/plain", System.Text.Encoding.UTF8);
}
}
}
}

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
namespace ApiDatosGuadex.Filtros
{
public class FiltroAutenticacionBasica : Attribute, IAuthorizationFilter
{
private readonly string _usuarioPermitido;
private readonly string _contrasenaPermitida;
public FiltroAutenticacionBasica(IConfiguration configuration)
{
var authSettings = configuration.GetSection("Authentication");
_usuarioPermitido = authSettings["Username"];
_contrasenaPermitida = authSettings["Password"];
}
public void OnAuthorization(AuthorizationFilterContext contexto)
{
var encabezadoAutorizacion = contexto.HttpContext.Request.Headers["Authorization"].ToString();
if (string.IsNullOrEmpty(encabezadoAutorizacion) || !encabezadoAutorizacion.StartsWith("Basic "))
{
contexto.Result = new UnauthorizedResult();
return;
}
var credencialesCodificadas = encabezadoAutorizacion.Substring("Basic ".Length).Trim();
var credencialesDecodificadas = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(credencialesCodificadas));
var partes = credencialesDecodificadas.Split(':');
if (partes.Length != 2 || partes[0] != _usuarioPermitido || partes[1] != _contrasenaPermitida)
{
contexto.Result = new UnauthorizedResult();
}
}
}
}

View File

@@ -0,0 +1,7 @@
namespace ApiDatosGuadex.Models
{
public class MensajeViewModel
{
public string Mensaje { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
using ApiDatosGuadex.Filtros;
var builder = WebApplication.CreateBuilder(args);
// Agregar servicios al contenedor
builder.Services.AddControllersWithViews();
// Registrar el filtro de autenticaci<63>n como servicio
builder.Services.AddScoped<FiltroAutenticacionBasica>();
// Agregar Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configuraci<63>n del pipeline de solicitudes HTTP
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthorization();
app.MapControllers();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();

View File

@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:12379",
"sslPort": 44309
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5188",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7029;http://localhost:5188",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,3 @@
@ViewData["Mensaje"]

View File

@@ -0,0 +1,4 @@
@ViewData["Mensaje"]

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Authentication": {
"Username": "guadex",
"Password": "tsguadex..-"
}
}