first commit
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog;
|
||||
using Landmark.OLA.Application.Services;
|
||||
using Landmark.OLA.Application.Services.Exceptions;
|
||||
using Landmark.OLA.Models.Individuals;
|
||||
using OnlineBankingAuth.Tokens;
|
||||
|
||||
namespace Landmark.OLA.Application.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class IndividualController : ControllerBase
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly ITokenService _tokenService;
|
||||
|
||||
public IndividualController(ITokenService tokenService,
|
||||
ICoreService coreService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_tokenService = tokenService;
|
||||
}
|
||||
|
||||
// GET: api/Individual/self
|
||||
[HttpGet("self", Name = "GetIndividual")]
|
||||
[ProducesResponseType(typeof(Individual), 200)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
[ProducesResponseType(503)]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = _tokenService.GetAuthenticatedDataFromCookie(HttpContext);
|
||||
if (token?.IndividualID == null )
|
||||
{
|
||||
Log.Error("Unauthorized request for 'Self' in Loan API, denying.");
|
||||
if (token?.MemberID != null)
|
||||
{
|
||||
// This isn't logging the security token, but the actual token content.
|
||||
Log.Error($"Unauthorized request was on behalf of {@token}");
|
||||
}
|
||||
return Unauthorized();
|
||||
}
|
||||
var individual = await _coreService.GetIndividual(token.MemberID);
|
||||
return Ok(individual);
|
||||
}
|
||||
catch (CoreUnavailableException cue)
|
||||
{
|
||||
Log.Error(cue.Message);
|
||||
return StatusCode((int)HttpStatusCode.ServiceUnavailable);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user