using System; using System.Collections.Generic; using System.Threading.Tasks; using LCU.API.Collections.RepoApi.Configuration; using LCU.API.Collections.RepoApi.Models.Responses; using LCU.API.Collections.RepoApi.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.FeatureManagement.Mvc; using Serilog; namespace LCU.API.Collections.RepoApi.Controllers { [Route("api/[controller]")] [ApiController] [FeatureGate(FeatureFlags.EnableControllers)] public class FactoidController : RepoControllerBase { private readonly IFactoidService _factoidService; public FactoidController(IHttpContextAccessor httpContextAccessor, IFactoidService factoidService) : base(httpContextAccessor) { _factoidService = factoidService; } // GET: api/Factoid [HttpGet(Name = "GetAllFactoids")] [ProducesResponseType(typeof(IEnumerable), 200)] [ProducesResponseType(500)] public async Task GetAllFactoids() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = new List() { await _factoidService.GetAllAccountsO4R(), await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate), await _factoidService.GetCurrentInventory(), await _factoidService.GetPercentFloorPrice(lowDate, highDate), await _factoidService.GetCurrentlyOnHold(), await _factoidService.GetRecentlyRedeemed(lowDate, highDate), await _factoidService.GetRecentlyRepoed(lowDate, highDate), await _factoidService.GetGetAvgDaysDelqToO4R(lowDate, highDate), await _factoidService.GetGetAvgDaysRepoToSold(lowDate, highDate), await _factoidService.GetRecentlySold(lowDate, highDate) }; return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/CurrentInventory [HttpGet("CurrentInventory", Name = "GetCurrentInventory")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetCurrentInventory() { try { var factoidResponse = await _factoidService.GetCurrentInventory(); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/AccountsO4R [HttpGet("AccountsO4R", Name = "GetAllAccountsInO4R")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetAllAccountsO4R() { try { var factoidResponse = await _factoidService.GetAllAccountsO4R(); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/PercentFloor [HttpGet("PercentFloor", Name = "GetPercentFloor")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetPercentFloor() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetPercentFloorPrice(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/RecentlyRedeemed [HttpGet("RecentlyRedeemed", Name = "GetRecentlyRedeemed")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetRecentlyRedeemed() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetRecentlyRedeemed(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/AvgDaysO4RToREPO [HttpGet("AvgDaysO4RToREPO", Name = "GetAvgDaysO4RToRepo")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetAvgDaysO4RToRepo() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/AvgDaysDelqToO4R [HttpGet("AvgDaysDelqToO4R", Name = "GetAvgDaysDelqToO4R")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetAvgDaysDelqToO4R() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetGetAvgDaysDelqToO4R(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/AvgDaysRepoToSold [HttpGet("AvgDaysRepoToSold", Name = "GetAvgDaysRepoToSold")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetAvgDaysRepoToSold() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetGetAvgDaysRepoToSold(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/CurrentOnHold [HttpGet("CurrentOnHold", Name = "GetCurrentOnHold")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetCurrentOnHold() { try { var factoidResponse = await _factoidService.GetCurrentlyOnHold(); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/RecentlyRepoed [HttpGet("RecentlyRepoed", Name = "GetRecentlyRepoed")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetRecentlyRepoed() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetRecentlyRepoed(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } // GET: api/factoid/RecentlySold [HttpGet("RecentlySold", Name = "GetRecentlySold")] [ProducesResponseType(typeof(FactoidResponse), 200)] [ProducesResponseType(500)] public async Task GetRecentlySold() { try { var highDate = DateTime.Today; var lowDate = highDate.Subtract(TimeSpan.FromDays(30)); var factoidResponse = await _factoidService.GetRecentlySold(lowDate, highDate); return Ok(factoidResponse); } catch (Exception ex) { Log.Error(ex, $"Failure in {GetType().Name} at Factoid: {GetInvokerAsyncMethodName()}"); return StatusCode(StatusCodes.Status500InternalServerError); } } } }