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), 200)] [ProducesResponseType(204)] [ProducesResponseType(500)] public async Task 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 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 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 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 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); } } }