54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using LCU.API.Internal.LoanRate.Services;
|
|
using LCU.API.Internal.LoanRate.Services.LoanRateOperationServices;
|
|
using LCU.Library.Internal.LcuClassPatterns.Crud.Controllers;
|
|
using LCU.Library.Internal.LoanRateModels.Requests;
|
|
using LCU.Library.Internal.LoanRateModels.Responses.Validation;
|
|
using LCU.Library.Internal.LoanRateModels.Responses.Validation.RateSheetValidations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LCU.API.Internal.LoanRate.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class RateValidationController : ControllerBase
|
|
{
|
|
private readonly IRateValidationService _rateValidationService;
|
|
|
|
public RateValidationController(IRateValidationService rateValidationService)
|
|
{
|
|
_rateValidationService = rateValidationService;
|
|
}
|
|
|
|
[HttpPost("Validate")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(RateSheetValidationResult), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Validate([FromBody] List<Rate> rates)
|
|
{
|
|
try
|
|
{
|
|
if (rates is null || rates.Count == 0)
|
|
{
|
|
return BadRequest("Rates cannot be null.");
|
|
}
|
|
|
|
var result = await _rateValidationService.ValidateAsync(rates);
|
|
if (result is 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);
|
|
}
|
|
}
|
|
} |