using Microsoft.AspNetCore.Mvc;
using FindAndDrive.Domain.Interfaces.Services;
using FindAndDrive.Domain.Models.DTO.Request;
using Microsoft.AspNetCore.Authorization;
using FindAndDrive.Domain.Models.DTO;
using FindAndDrive.Domain.Models.DTO.Response;
using System.Net;
using FindAndDrive.Domain.Models.Gateways.Transunion;
using FindAndDrive.Domain.Models.Gateways.Experian;
namespace FindAndDrive.API.Controllers;
[Authorize(nameof(Permissions.Financing))]
[ApiController]
[Route("api/[controller]")]
public class FinancingController : ControllerBase
{
private readonly IFinancingService _financingService;
public FinancingController(IFinancingService financingService)
{
_financingService = financingService;
}
///
/// Gets monthly and total amounts, writes the applicant to the db and return its id
///
/// This endpoint is the initial endpoint in which we write the first data for our applicant to the database, and return a rough estimate for monthly and total values.
[HttpPost("Pre-Qualification")]
[ProducesResponseType(typeof(PreVettingResponse), (int)HttpStatusCode.OK)]
public async Task Financing([FromBody] PreVettingRequest request)
{
var clientId = HttpContext.User.Claims.First(f => f.Type == "ClientId").Value;
var response = await _financingService.FinancingCalc(request, Guid.Parse(clientId));
return Ok(response);
}
///
/// Writes data from the prediction model to the given applicant
///
/// In this endpoint we make calls to Experian and Transunion, and then apply the prediction model to the data. It writes all the results to our database.
[HttpPost("Prediction")]
[ProducesResponseType(typeof(AnalyticsResponse), (int)HttpStatusCode.OK)]
public async Task Analytics([FromBody] AnalyticsRequest request) {
var clientId = HttpContext.User.Claims.First(f => f.Type == "ClientId").Value;
var apiKey = HttpContext.User.Claims.First(f => f.Type == "apiKeyId").Value;
var response = await _financingService.Analytics(request, Guid.Parse(clientId), Guid.Parse(apiKey));
return Ok(response);
}
///
///
/// Returns all data on a given applicant
///
/// Enter in your applicantId which you recieved from the first two endpoints, and then the response will be all the infomation we have on that applicant.
[HttpGet("GetApplicantById")]
[ProducesResponseType(typeof(ApplicantResponse), (int)HttpStatusCode.OK)]
public async Task GetApplicantById(Guid id)
{
var clientId = HttpContext.User.Claims.First(f => f.Type == "ClientId").Value;
var response = await _financingService.GetApplicantById(id, Guid.Parse(clientId));
return Ok(response);
}
[ApiExplorerSettings(IgnoreApi = true)]
[HttpPost("Experian")]
[ProducesResponseType(typeof(AnalyticsResponse), (int)HttpStatusCode.OK)]
public async Task Experian([FromBody] ExperianIndependentRequest request)
{
var response = await _financingService.ExperianIndependentCall(request);
return Ok(response);
}
[ApiExplorerSettings(IgnoreApi = true)]
[HttpPost("Transunion")]
[ProducesResponseType(typeof(AnalyticsResponse), (int)HttpStatusCode.OK)]
public async Task TransUnion([FromBody] TransunionIndependentRequest request)
{
var response = await _financingService.TransUnionIndependentCall(request);
return Ok(response);
}
}