Neue DTOs und Befehle zur Erstellung von Umschlägen in CreateEnvelope.cs hinzugefügt. Aktualisierte Projektdateien, um net7.0, net8.0 und net9.0 zu unterstützen. Refactored EnvelopeController für bessere Struktur und Fehlerbehandlung. Einführung einer Methode zur Erstellung von Umschlägen in EnvelopeReceiverController unter Verwendung von IMediator. Allgemeine Verbesserungen der Funktionalität und Kompatibilität.
154 lines
6.4 KiB
C#
154 lines
6.4 KiB
C#
using DigitalData.Core.DTO;
|
|
using EnvelopeGenerator.Application.Contracts.Services;
|
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Commands;
|
|
using EnvelopeGenerator.Common.My.Resources;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class EnvelopeReceiverController : ControllerBase
|
|
{
|
|
private readonly ILogger<EnvelopeReceiverController> _logger;
|
|
|
|
private readonly IEnvelopeReceiverService _erService;
|
|
|
|
private readonly IMediator _mediator;
|
|
|
|
public EnvelopeReceiverController(ILogger<EnvelopeReceiverController> logger, IEnvelopeReceiverService envelopeReceiverService, IMediator mediator)
|
|
{
|
|
_logger = logger;
|
|
_erService = envelopeReceiverService;
|
|
_mediator = mediator;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetEnvelopeReceiver([FromQuery] int? min_status = null, [FromQuery] int? max_status = null, [FromQuery] int[]? ignore_status = null)
|
|
{
|
|
try
|
|
{
|
|
var username = User.GetUsername();
|
|
|
|
if (username is null)
|
|
{
|
|
_logger.LogError(@"Envelope Receiver dto cannot be sent because username claim is null. Potential authentication and authorization error. The value of other claims are [id: {id}], [username: {username}], [name: {name}], [prename: {prename}], [email: {email}].",
|
|
User.GetId(), User.GetUsername(), User.GetName(), User.GetPrename(), User.GetEmail());
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
|
|
ignore_status ??= Array.Empty<int>();
|
|
|
|
return await _erService.ReadByUsernameAsync(username: username, min_status: min_status, max_status: max_status, ignore_statuses: ignore_status).ThenAsync(
|
|
Success: Ok,
|
|
Fail: IActionResult (msg, ntc) =>
|
|
{
|
|
_logger.LogNotice(ntc);
|
|
return StatusCode(StatusCodes.Status500InternalServerError, msg);
|
|
});
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError(ex, "An unexpected error occurred. {message}", ex.Message);
|
|
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("receiver-name/{mail}")]
|
|
public async Task<IActionResult> GetReceiverName([FromRoute] string mail)
|
|
{
|
|
try
|
|
{
|
|
return await _erService.ReadLastUsedReceiverNameByMail(mail).ThenAsync(
|
|
Success: res => res is null ? Ok(string.Empty) : Ok(res),
|
|
Fail: IActionResult (msg, ntc) =>
|
|
{
|
|
if (ntc.HasFlag(Flag.NotFound))
|
|
return NotFound();
|
|
|
|
_logger.LogNotice(ntc);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
});
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("secret")]
|
|
[Authorize]
|
|
public async Task<IActionResult> GetSecretAsync([FromQuery] string uuid)
|
|
{
|
|
try
|
|
{
|
|
return await _erService.ReadWithSecretByUuidAsync(uuid: uuid).ThenAsync(
|
|
Success: Ok,
|
|
Fail: IActionResult (msg, ntc) =>
|
|
{
|
|
_logger.LogNotice(ntc);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{message}", ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Datenübertragungsobjekt mit Informationen zu Umschlägen, Empfängern und Unterschriften.
|
|
/// </summary>
|
|
/// <param name="envelope"></param>
|
|
/// <param name="cancellationToken">Token to cancel the operation</param>
|
|
/// <returns>HTTP-Antwort</returns>
|
|
/// <remarks>
|
|
/// Sample request:
|
|
///
|
|
/// POST /api/envelope
|
|
/// {
|
|
/// "title": "Vertragsdokument",
|
|
/// "message": "Bitte unterschreiben Sie dieses Dokument.",
|
|
/// "document": {
|
|
/// "dataAsBase64": "dGVzdC1iYXNlNjQtZGF0YQ=="
|
|
/// },
|
|
/// "receivers": [
|
|
/// {
|
|
/// "emailAddress": "example@example.com",
|
|
/// "signatures": [
|
|
/// {
|
|
/// "x": 100,
|
|
/// "y": 200,
|
|
/// "page": 1
|
|
/// }
|
|
/// ],
|
|
/// "name": "Max Mustermann",
|
|
/// "phoneNumber": "+49123456789"
|
|
/// }
|
|
/// ],
|
|
/// "language": "de-DE",
|
|
/// "expiresWhen": "2025-12-31T23:59:59Z",
|
|
/// "expiresWarningWhen": "2025-12-24T23:59:59Z",
|
|
/// "contractType": 1,
|
|
/// "tfaEnabled": false
|
|
/// }
|
|
///
|
|
/// </remarks>
|
|
/// <response code="202">Envelope-Erstellung und Sendeprozessbefehl erfolgreich</response>
|
|
/// <response code="400">Wenn ein Fehler im HTTP-Body auftritt</response>
|
|
/// <response code="401">Wenn kein autorisierter Token vorhanden ist</response>
|
|
/// <response code="500">Es handelt sich um einen unerwarteten Fehler. Die Protokolle sollten überprüft werden.</response>
|
|
[Authorize]
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateAsync([FromBody] CreateEnvelopeCommand envelope, CancellationToken cancellationToken)
|
|
{
|
|
await _mediator.Send(envelope, cancellationToken);
|
|
return Accepted();
|
|
}
|
|
}
|
|
} |