60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using LCU.API.Internal.Operations.IncentiveApi.HostedServices;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Controllers
|
|
{
|
|
public class HostedServicesController : ControllerBase
|
|
{
|
|
private readonly IApplicationDbIntegrityHostedService _applicationDbIntegrityHostedServiceStarter;
|
|
|
|
public HostedServicesController(IApplicationDbIntegrityHostedService applicationDbIntegrityHostedServiceStarter)
|
|
{
|
|
_applicationDbIntegrityHostedServiceStarter = applicationDbIntegrityHostedServiceStarter;
|
|
}
|
|
|
|
[HttpPost("StartApplicationDbIntegrity", Name = "StartApplicationDbIntegrity")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> StartApplicationDbIntegrity()
|
|
{
|
|
try
|
|
{
|
|
await _applicationDbIntegrityHostedServiceStarter.StartAsync();
|
|
return Ok();
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpPost("StopApplicationDbIntegrity", Name = "StopApplicationDbIntegrity")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> StopApplicationDbIntegrity()
|
|
{
|
|
try
|
|
{
|
|
await _applicationDbIntegrityHostedServiceStarter.StopAsync();
|
|
return Ok();
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|
|
}
|