147 lines
4.9 KiB
C#
147 lines
4.9 KiB
C#
using ReserveManagementSystemApi.Services;
|
|
using ReserveManagementSystemLib.Models;
|
|
|
|
namespace ReserveManagementSystemApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class LoanController : ControllerBase
|
|
{
|
|
private readonly ILoanService _loanService;
|
|
public LoanController(ILoanService loanService)
|
|
{
|
|
_loanService = loanService;
|
|
}
|
|
|
|
[HttpGet(Name = "GetAllLoans")]
|
|
[ProducesResponseType(typeof(IEnumerable<Loan>), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.GetAllAsync();
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Failure returning Loans");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpPost("SearchLoans", Name = "SearchLoans")]
|
|
[ProducesResponseType(typeof(PaginatedListResponse), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Post([FromBody]LoanFilter filter)
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.GetFilteredAsync(filter);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Failure returning Filtered Loans");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("SearchMembers/{searchText}", Name = "SearchMembers")]
|
|
[ProducesResponseType(typeof(string), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> SearchMembers(string searchText)
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.SearchMembers(searchText);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, $"Failure returning members");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("SearchLoanNumbers/{searchText}", Name = "SearchLoanNumbers")]
|
|
[ProducesResponseType(typeof(string), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> SearchLoanNumbers(string searchText)
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.SearchLoanNumbers(searchText);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, $"Failure returning loan numbers");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("SearchApplicationIds/{searchText}", Name = "SearchApplicationIds")]
|
|
[ProducesResponseType(typeof(string), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> SearchApplicationIds(string searchText)
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.SearchApplicationIds(searchText);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, $"Failure returning application ids");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("GetById/{loanId}", Name = "GetLoanById")]
|
|
[ProducesResponseType(typeof(Loan), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetById(int loanId)
|
|
{
|
|
try
|
|
{
|
|
var result = await _loanService.GetByIdAsync(loanId);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, $"Failure returning loan with id {loanId}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpPost("CalculateReserve", Name = "CalculateReserve")]
|
|
public async Task<LoanReserve> Post([FromBody] LoanReserveInput input)
|
|
{
|
|
try
|
|
{
|
|
return await _loanService.GetLoanReserveAsync(input);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error("Failure to Calculate Loan Reserve: {0} {1}", e.Message, e.StackTrace);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
[HttpPost("CalculateChargeback", Name = "CalculateChargeback")]
|
|
public async Task<LoanChargeback> Post([FromBody] LoanChargebackInput input)
|
|
{
|
|
try
|
|
{
|
|
return await _loanService.GetLoanChargebackAsync(input);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error("Failure to Calculate Loan Chargeback: {0} {1}", e.Message, e.StackTrace);
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|