133 lines
3.7 KiB
C#
133 lines
3.7 KiB
C#
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using LCU.Library.Internal.Status.Services;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class StatusController : ControllerBase
|
|
{
|
|
private readonly IApiHealthCheckService _apiHealthCheckService;
|
|
private readonly IDateTime _dateTime;
|
|
|
|
public StatusController(IApiHealthCheckService apiHealthCheckService, IDateTime dateTime)
|
|
{
|
|
_apiHealthCheckService = apiHealthCheckService;
|
|
_dateTime = dateTime;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult Get()
|
|
{
|
|
try
|
|
{
|
|
return Ok(_apiHealthCheckService.CheckApiHealthAndBuildEnvironmentView());
|
|
}
|
|
catch (ServiceException exception)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, exception.Message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("LocalTime")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult GetLocalTime()
|
|
{
|
|
try
|
|
{
|
|
return Ok(_dateTime.Now);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("UtcTime")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult GetUTCTime()
|
|
{
|
|
try
|
|
{
|
|
return Ok(_dateTime.UTCNow);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("WindowsCstTime")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult GetWindowsCSTTime()
|
|
{
|
|
try
|
|
{
|
|
return Ok(_dateTime.CSTWindowsNow);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("LinuxCstTime")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult GetLinuxCSTTime()
|
|
{
|
|
try
|
|
{
|
|
return Ok(_dateTime.CSTLinuxNow);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("ConvertCSTToUTCWindows/{dateTimeString}")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult ConvertCSTToUTCWindows(string dateTimeString)
|
|
{
|
|
try
|
|
{
|
|
var convertedTime = _dateTime.ConvertDateTimeFromCSTToUTCWindows(dateTimeString);
|
|
return Ok(convertedTime);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("ConvertCSTToUTCLinux/{dateTimeString}")]
|
|
[ProducesResponseType(200)]
|
|
public IActionResult ConvertCSTToUTCLinux(string dateTimeString)
|
|
{
|
|
try
|
|
{
|
|
var convertedTime = _dateTime.ConvertDateTimeFromCSTToUTCLinux(dateTimeString);
|
|
return Ok(convertedTime);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name}");
|
|
return StatusCode((int) System.Net.HttpStatusCode.InternalServerError);
|
|
}
|
|
}
|
|
}
|