Files
monorepo/LCU.API.Internal.Dispatcher/LCU.Api.Internal.Dispatcher/Controllers/CleanUpJobSettingController.cs
T
2026-03-24 15:26:03 -05:00

162 lines
4.8 KiB
C#

using LCU.Api.Internal.Dispatcher.Services;
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace LCU.Api.Internal.Dispatcher.Controllers;
[ApiController]
[Route("api/[controller]")]
public class CleanUpJobSettingController : ControllerBase
{
private readonly ICleanUpJobSettingService _cleanUpJobSettingService;
public CleanUpJobSettingController(ICleanUpJobSettingService cleanUpJobSettingService)
{
_cleanUpJobSettingService = cleanUpJobSettingService;
}
[HttpGet("GetAllCleanUpJobSetting", Name = "GetAllCleanUpJobSetting")]
[ProducesResponseType(typeof(IEnumerable<CleanUpJobSetting>), 200)]
[ProducesResponseType(204)]
[ProducesResponseType(500)]
public async Task<IActionResult> Get()
{
try
{
var result = await _cleanUpJobSettingService.GetAsync();
if (result == null || !result.Any())
{
return NoContent();
}
return Ok(result);
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpGet("GetByCleanUpJobSettingIdAsync", Name = "GetByCleanUpJobSettingIdAsync")]
[ProducesResponseType(typeof(CleanUpJobSetting), 200)]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public async Task<IActionResult> GetByCleanUpJobSettingIdAsync(int cleanUpJobSettingId)
{
try
{
if (cleanUpJobSettingId <= 0)
{
return BadRequest("Invalid CleanUpJobSettingId.");
}
var result = await _cleanUpJobSettingService.GetByCleanUpJobSettingIdAsync(cleanUpJobSettingId);
if (result == null)
{
return NoContent();
}
return Ok(result);
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpPost]
[ProducesResponseType(typeof(CleanUpJobSetting), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(406)]
[ProducesResponseType(500)]
public async Task<IActionResult> Post([FromBody] CleanUpJobSetting request)
{
try
{
var result = await _cleanUpJobSettingService.SaveAsync(request);
if (result == null)
{
return StatusCode(StatusCodes.Status406NotAcceptable);
}
return Ok(result);
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpPut()]
[ProducesResponseType(typeof(CleanUpJobSetting), 200)]
[ProducesResponseType(406)]
[ProducesResponseType(500)]
public async Task<IActionResult> Put([FromBody] CleanUpJobSetting request)
{
try
{
var result = await _cleanUpJobSettingService.UpdateAsync(request);
if (result == null)
{
return StatusCode(StatusCodes.Status406NotAcceptable);
}
return Ok(result);
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[HttpDelete()]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public async Task<IActionResult> Delete(int cleanUpJobSettingId)
{
try
{
if (cleanUpJobSettingId <= 0)
{
return BadRequest("Invalid CleanUpJobSettingId");
}
await _cleanUpJobSettingService.DeleteAsync(cleanUpJobSettingId);
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}