feat(api): Hinzufügen des EnvelopeControllers mit GetCurrentAsync-Methode zur Umschlagabfrage
- Implementierung des `EnvelopeController` in der Route `api/envelope` mit der Methode `GetCurrentAsync`, um Umschläge basierend auf der Benutzer-ID abzurufen. - Fehlerbehandlung hinzugefügt, wenn die Benutzer-ID keine Ganzzahl ist, mit einem möglichen Problem bei der Erstellung der Claims-Liste.
This commit is contained in:
parent
8d680992b7
commit
e3fbf4fc77
@ -0,0 +1,50 @@
|
|||||||
|
using DigitalData.Core.DTO;
|
||||||
|
using EnvelopeGenerator.Application.Contracts;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class EnvelopeController : ControllerBase
|
||||||
|
{
|
||||||
|
private ILogger<EnvelopeController> _logger;
|
||||||
|
private readonly IEnvelopeService _envelopeService;
|
||||||
|
|
||||||
|
public EnvelopeController(ILogger<EnvelopeController> logger, IEnvelopeService envelopeService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_envelopeService = envelopeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> GetCurrentAsync(bool current_user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var id = this.GetId();
|
||||||
|
|
||||||
|
if (id is int intId)
|
||||||
|
return await _envelopeService.ReadByIdAsync(intId).ThenAsync(
|
||||||
|
Success: Ok,
|
||||||
|
Fail: IActionResult (msg, ntc) =>
|
||||||
|
{
|
||||||
|
_logger.LogNotice(ntc);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
});
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogError("Despite successful authorization, the 'api/envelope' route encountered an issue: the user ID is not recognized as an integer. This may be due to the removal of the ID during the creation of the claims list.");
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "{Message}", ex.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,8 +17,6 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get([FromQuery] string? emailAddress = null, [FromQuery] string? signature = null)
|
public async Task<IActionResult> Get([FromQuery] string? emailAddress = null, [FromQuery] string? signature = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user