150 lines
4.7 KiB
C#
150 lines
4.7 KiB
C#
using Serilog;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using LCU.API.Internal.DocumentIngestor.Services;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
|
using LCU.Library.Internal.Exceptions;
|
|
namespace LCU.API.Internal.DocumentIngestor.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class PdfPartitionerLogController : ControllerBase
|
|
{
|
|
private readonly IPdfPartitionerLogService _pdfPartitionerLogServiceService;
|
|
|
|
public PdfPartitionerLogController(IPdfPartitionerLogService pdfPartitionerLogServiceService)
|
|
{
|
|
_pdfPartitionerLogServiceService = pdfPartitionerLogServiceService;
|
|
}
|
|
|
|
[HttpGet()]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(PdfPartitionerLog), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
try
|
|
{
|
|
var result = await _pdfPartitionerLogServiceService.GetAsync();
|
|
if (result == null || !result.Any())
|
|
{
|
|
return NoContent();
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("{id:int}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(PdfPartitionerLog), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetById(int id)
|
|
{
|
|
try
|
|
{
|
|
if (id <= 0)
|
|
{
|
|
return BadRequest($"Id {id} is invalid.");
|
|
}
|
|
|
|
var result = await _pdfPartitionerLogServiceService.GetByIdAsync(id);
|
|
if (result == null)
|
|
{
|
|
return NoContent();
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("GetByPdfPartitionerRunInfoId/{pdfPartitionerRunInfoId:guid}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(PdfPartitionerLog), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetByPdfPartitionerRunInfoId(Guid pdfPartitionerRunInfoId)
|
|
{
|
|
try
|
|
{
|
|
var result = await _pdfPartitionerLogServiceService.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId);
|
|
if (result == null || !result.Any())
|
|
{
|
|
return NoContent();
|
|
}
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(typeof(PdfPartitionerLog), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Post([FromBody] PdfPartitionerLog pdfPartitionerLog)
|
|
{
|
|
try
|
|
{
|
|
var result = await _pdfPartitionerLogServiceService.SaveAsync(pdfPartitionerLog);
|
|
return CreatedAtAction(nameof(GetById), new { id = result.PdfPartitionerLogId }, result);
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpDelete("{id:int}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Delete(int id)
|
|
{
|
|
try
|
|
{
|
|
await _pdfPartitionerLogServiceService.Delete(id);
|
|
return Ok();
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
} |