using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using RSecurityBackend.Models.Audit.Db;
using RSecurityBackend.Models.Auth.Memory;
using RSecurityBackend.Models.Generic;
using RSecurityBackend.Services;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace RSecurityBackend.Controllers
{
///
/// Audit Log Controller Base
///
[Produces("application/json")]
[Route("api/auditlogs")]
public abstract class AuditLogControllerBase : Controller
{
///
/// get all audit logs ordered by time
///
///
///
///
///
[HttpGet]
[Authorize(Policy = SecurableItem.AuditLogEntityShortName + ":" + SecurableItem.ViewOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task Get([FromQuery]PagingParameterModel paging, string userName, bool orderByTimeDescending)
{
RServiceResult<(PaginationMetadata PagingMeta, REvent[] Items)> itemsInfo
= await _auditLogService.GetAll(paging, userName, orderByTimeDescending);
if (!string.IsNullOrEmpty(itemsInfo.ExceptionString))
{
return BadRequest(itemsInfo.ExceptionString);
}
// Paging Header
HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(itemsInfo.Result.PagingMeta));
return Ok(itemsInfo.Result.Items);
}
///
/// constructor
///
///
///
public AuditLogControllerBase(IAuditLogService auditLogService)
{
_auditLogService = auditLogService;
}
///
/// Artifact Service
///
protected readonly IAuditLogService _auditLogService;
}
}