feat(controller): add GetAllAsync endpoint to HistoryController

- Added a new `GetAllAsync` method to HistoryController to retrieve envelope histories.
- Included query parameters for filtering by envelopeId, userReference, referenceType, status, and boolean flags for sender and receiver.
- Implemented validation of `referenceType` with `ReferenceType` enum, throwing an error for invalid values.
This commit is contained in:
Developer 02
2024-09-07 00:08:55 +02:00
parent 75fff426bc
commit 7bc2695da4
2 changed files with 28 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ namespace EnvelopeGenerator.Domain.Entities
[Required]
[Column("USER_REFERENCE", TypeName = "nvarchar(128)")]
public string UserReference { get; set; }
public required string UserReference { get; init; }
[Required]
[Column("STATUS")]

View File

@@ -1,6 +1,8 @@
using EnvelopeGenerator.Application.Contracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.GeneratorAPI.Controllers
{
@@ -18,5 +20,29 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
_logger = logger;
_service = service;
}
[HttpGet]
public async Task<IActionResult> GetAllAsync([FromQuery] int? envelopeId = null, [FromQuery] string? userReference = null, [FromQuery] int? referenceType = null, [FromQuery] int? status = null, [FromQuery] bool withSender = false, [FromQuery] bool withReceiver = false)
{
ReferenceType? refTypEnum = null;
if (referenceType is int refTypInt)
{
if (Enum.IsDefined(typeof(ReferenceType), refTypInt))
refTypEnum = (ReferenceType)refTypInt;
}
else
throw new ArgumentException($"The provided referenceType '{referenceType}' is not valid. It must correspond to a valid value in the {nameof(ReferenceType)} enum.");
var histories = await _service.ReadAsync(
envelopeId: envelopeId,
userReference: userReference,
referenceType: refTypEnum,
status: status,
withSender: withSender,
withReceiver: withReceiver);
return Ok(histories);
}
}
}