Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestor/Controllers/DocumentReprocessingController.cs
T
2026-03-25 14:50:13 -05:00

111 lines
3.8 KiB
C#

using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.Library.Internal.ApiSecurity.Attributes;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Serilog;
namespace LCU.API.Internal.DocumentIngestor.Controllers;
[ApiController]
[Route("[controller]")]
public class DocumentReprocessingController : ControllerBase
{
private readonly IDocumentReprocessingService _reprocessingService;
public DocumentReprocessingController(IDocumentReprocessingService reprocessingService)
{
_reprocessingService = reprocessingService;
}
[ApiKey]
[HttpPost("QueueReprocessDocumentByDocumentProcessingInfoId/{documentProcessingInfoId:int}/{userName}")]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
[ProducesResponseType(500)]
public async Task<IActionResult> QueueReprocessDocumentByDocumentProcessingInfoId(int documentProcessingInfoId, string userName)
{
try
{
if (documentProcessingInfoId <= 0 || string.IsNullOrWhiteSpace(userName))
{
return BadRequest($"documentProcessingInfoId and userName are required.");
}
await _reprocessingService.QueueReprocessDocumentByDocumentProcessingInfoId(documentProcessingInfoId, userName);
return Accepted();
}
catch (ArgumentNullException exception)
{
return StatusCode(StatusCodes.Status404NotFound, exception.Message);
}
catch (ServiceException exception)
{
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("QueueOverrideDocumentByDocumentProcessingInfoId")]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
[ProducesResponseType(500)]
public async Task<IActionResult> QueueOverrideDocumentByDocumentProcessingInfoId(OwnerOverrideInfo ownerOverrideRequest)
{
try
{
await _reprocessingService.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideRequest);
return Accepted();
}
catch (ArgumentNullException exception)
{
return StatusCode(StatusCodes.Status404NotFound, exception.Message);
}
catch (ServiceException exception)
{
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("QueueReprocessAllCriticalFailures/{userName}")]
[ProducesResponseType(202)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
[ProducesResponseType(500)]
public async Task<IActionResult> QueueReprocessAllCriticalFailures(string userName)
{
try
{
if (string.IsNullOrWhiteSpace(userName))
{
return BadRequest($"UserName is required.");
}
await _reprocessingService.QueueReprocessAllCriticalFailures(userName);
return Accepted();
}
catch (ServiceException exception)
{
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}