refactor(ReadHistoryQuery): update to not throw exception.

- update controller to throw NotFound if the list is empty
This commit is contained in:
Developer 02
2025-08-28 18:30:27 +02:00
parent f7c988be9b
commit dad43de8b1
5 changed files with 7 additions and 12 deletions

View File

@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using static EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Application.Histories.Queries;
using DigitalData.Core.Client;
using EnvelopeGenerator.Application.Extensions;
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
@@ -107,8 +109,7 @@ public class HistoryController : ControllerBase
[Authorize]
public async Task<IActionResult> GetAllAsync([FromQuery] ReadHistoryQuery historyQuery)
{
var history = await _mediator.Send(historyQuery);
var history = await _mediator.Send(historyQuery).ThrowIfEmpty(Exceptions.NotFound);
return Ok((historyQuery.OnlyLast ?? false) ? history.MaxBy(h => h.AddedWhen) : history);
}
}