feat(ProfileController): Hinzufügen von ProfileController mit GET-Endpunkt unter Verwendung von MediatR

- Implementiert die Aktion `GetAsync` zum Abrufen von Profildaten über MediatR
- Fügt die Attribute `[Authorize]` und `[APIKeyAuth]` für den gesicherten Zugriff hinzu
- Protokolliert Ausnahmen und gibt entsprechende HTTP-Statuscodes zurück
This commit is contained in:
tekh 2025-07-24 13:41:44 +02:00
parent c08c5aacf3
commit fe358623da
3 changed files with 17 additions and 54 deletions

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Authorization; using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using WorkFlow.API.Attributes; using WorkFlow.API.Attributes;
using WorkFlow.Application.Contracts; using WorkFlow.Application.Profiles;
using WorkFlow.Domain.Entities;
namespace WorkFlow.API.Controllers; namespace WorkFlow.API.Controllers;
@ -12,56 +12,23 @@ namespace WorkFlow.API.Controllers;
[Authorize] [Authorize]
public class ProfileController : ControllerBase public class ProfileController : ControllerBase
{ {
public static readonly Profile Default = new()
{
Id = 1,
TypeId = 1,
Caption = "VA Freigabe",
Subtitle = "Freigabe in Rolle Verantwortlich",
CountObj = 2,
ForeColor = "Yellow",
BackColor = "Black",
Objects = new ProfileObject[]
{
new()
{
ObjStateId = 3,
ObjectId = 21601,
Headline1 = "Aveco Holding",
Headline2 = "Digital Data",
Subline1 = null,
Subline2 = "25 4711",
CmdCheckIn = ""
},
new()
{
ObjStateId = 4,
ObjectId = 21600,
Headline1 = "Aveco",
Headline2 = "Hammer AF",
Subline1 = null,
Subline2 = "456875",
CmdCheckIn = ""
}
}
};
private readonly ILogger<ProfileController> _logger; private readonly ILogger<ProfileController> _logger;
private readonly IProfileService _service; private readonly IMediator _mediator;
public ProfileController(ILogger<ProfileController> logger, IProfileService service)
public ProfileController(ILogger<ProfileController> logger, IMediator mediator)
{ {
_logger = logger; _logger = logger;
_service = service; _mediator = mediator;
} }
[HttpGet] [HttpGet]
[Authorize] public IActionResult GetAsync([FromQuery] ReadProfile profileQ)
public IActionResult GetAsync()
{ {
try try
{ {
return Ok(Default); var profile = _mediator.Send(profileQ);
return profile is null ? NotFound() : Ok(profile);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -69,5 +36,4 @@ public class ProfileController : ControllerBase
return StatusCode(500); return StatusCode(500);
} }
} }
} }

View File

@ -27,8 +27,12 @@ try
var config = builder.Configuration; var config = builder.Configuration;
// Add NLogger // Add NLogger
builder.Logging.ClearProviders(); builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
builder.Host.UseNLog(); if (!builder.Environment.IsDevelopment())
{
builder.Logging.ClearProviders();
builder.Host.UseNLog();
}
// Add services to the container // Add services to the container
var cnn_str = config.GetConnectionString("Default") ?? throw new("Default connection string not found."); var cnn_str = config.GetConnectionString("Default") ?? throw new("Default connection string not found.");

View File

@ -78,14 +78,7 @@
} }
}, },
"AuthClientParams": { "AuthClientParams": {
"Url": "https://localhost:7192/auth-hub", "Url": "http://172.24.12.39:9090/auth-hub",
"PublicKeys": [
{
"Issuer": "auth.digitaldata.works",
"Audience": "work-flow.digitaldata.works",
"Content": "-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3QCd7dH/xOUITFZbitMa/xnh8a0LyL6ZBvSRAwkI9ceplTRSHJXoM1oB+xtjWE1kOuHVLe941Tm03szS4+/rHIm0Ejva/KKlv7sPFAHE/pWuoPS303vOHgI4HAFcuwywA8CghUWzaaK5LU/Hl8srWwxBHv5hKIUjJFJygeAIENvFOZ1gFbB3MPEC99PiPOwAmfl4tMQUmSsFyspl/RWVi7bTv26ZE+m3KPcWppmvmYjXlSitxRaySxnfFvpca/qWfd/uUUg2KWKtpAwWVkqr0qD9v3TyKSgHoGDsrFpwSx8qufUJSinmZ1u/0iKl6TXeHubYS4C4SUSVjOWXymI2ZQIDAQAB-----END PUBLIC KEY-----"
}
],
"RetryDelay": "00:00:05" "RetryDelay": "00:00:05"
} }
} }