186 lines
5.6 KiB
C#
186 lines
5.6 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using Serilog;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Http;
|
|
using LCU.Api.Internal.ArchiverApi.Services;
|
|
using LCU.Api.Internal.ArchiverApi.Extensions;
|
|
using LCU.Library.Internal.ArchiverApiModel.Entities;
|
|
using LCU.Library.Internal.Exceptions;
|
|
namespace LCU.Api.Internal.ArchiverApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class RegexMappingController : ControllerBase
|
|
{
|
|
IRegexMappingService _regexMappingService;
|
|
public RegexMappingController(IRegexMappingService regexMappingService)
|
|
{
|
|
_regexMappingService = regexMappingService;
|
|
}
|
|
|
|
[HttpGet(Name = "GetAllRegex")]
|
|
[ProducesResponseType(typeof(IEnumerable<RegexMapping>), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
try
|
|
{
|
|
var result = await _regexMappingService.GetAsync();
|
|
return Ok(result);
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
[HttpGet("GetByRegexId/{regexMappingId:int}", Name = "GetByRegexId")]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(RegexMapping), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetByRegexMappingId(int regexMappingId)
|
|
{
|
|
try
|
|
{
|
|
if (regexMappingId <= 0)
|
|
{
|
|
return BadRequest("Invalid Id");
|
|
}
|
|
var result = await _regexMappingService.GetByRegexMappingIdAsync(regexMappingId);
|
|
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);
|
|
}
|
|
}
|
|
|
|
[HttpGet("GetByApplicationMappingId/{applicationMappingid:int}", Name = "GetByApplicationMappingId")]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(typeof(RegexMapping), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetByApplicationMappingId(int applicationMappingId)
|
|
{
|
|
try
|
|
{
|
|
if (applicationMappingId <= 0)
|
|
{
|
|
return BadRequest("Invalid Id");
|
|
}
|
|
var result = await _regexMappingService.GetByApplicationMappingIdAsync(applicationMappingId);
|
|
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(201)]
|
|
[ProducesResponseType(typeof(RegexMapping), 400)]
|
|
[ProducesResponseType(406)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> Post([FromBody] RegexMapping regexMapping)
|
|
{
|
|
try
|
|
{
|
|
var result = await _regexMappingService.SaveAsync(regexMapping);
|
|
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("UpdateRegex", Name = "UpdateRegex")]
|
|
[ProducesResponseType(typeof(RegexMapping), 200)]
|
|
[ProducesResponseType(406)]
|
|
[ProducesResponseType(500)]
|
|
public IActionResult Update([FromBody] RegexMapping regexMapping)
|
|
{
|
|
try
|
|
{
|
|
var result = _regexMappingService.Update(regexMapping);
|
|
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(typeof(RegexMapping), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
public IActionResult Delete(int regexId)
|
|
{
|
|
try
|
|
{
|
|
if (regexId <= 0)
|
|
{
|
|
return BadRequest("Invalid Id");
|
|
}
|
|
|
|
_regexMappingService.DeleteAsync(regexId);
|
|
return Ok();
|
|
}
|
|
catch (ServiceException)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.Error(exception, "Unexpected Exception");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|