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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user