Adding
This commit is contained in:
+104
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.Configuration;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Extensions;
|
||||
using LCU.API.Collections.RepoApi.Models.Filters;
|
||||
using LCU.API.Collections.RepoApi.Models.Responses;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.FeatureManagement.Mvc;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.API.Collections.RepoApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[FeatureGate(FeatureFlags.EnableControllers)]
|
||||
public class AuditRecordController : RepoControllerBase
|
||||
{
|
||||
private readonly IAuditRecordService _auditRecordService;
|
||||
|
||||
public AuditRecordController(
|
||||
IAuditRecordService repoAccountService,
|
||||
IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
|
||||
{
|
||||
_auditRecordService = repoAccountService;
|
||||
}
|
||||
|
||||
// GET: api/AuditRecord
|
||||
[HttpGet(Name = "GetAllAuditRecords")]
|
||||
[ProducesResponseType(typeof(PagedResponse<AuditRecord>), 200)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> Get([FromQuery] PageFilter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var searchResult = await _auditRecordService.ListAll(filter);
|
||||
var result = new PagedResponse<AuditRecord>(searchResult, filter, Url, Request);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/AuditRecord/5
|
||||
[HttpGet("{id}", Name = "GetAuditRecordById")]
|
||||
[ProducesResponseType(typeof(RepoAccount), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
return BadRequest("Invalid ID");
|
||||
}
|
||||
|
||||
var result = await _auditRecordService.Get(id);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (NotFoundException nfe)
|
||||
{
|
||||
return NotFound(nfe.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
// POST: api/RepoAccount
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(RepoAccount), 201)]
|
||||
[ProducesResponseType(typeof(List<string>), 400)]
|
||||
[ProducesResponseType(500)]
|
||||
public async Task<IActionResult> Post([FromBody] AuditRecord repoAccount)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState.GetErrorMessages());
|
||||
}
|
||||
|
||||
var result = await _auditRecordService.SaveAsync(repoAccount);
|
||||
return Ok( result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user