| | 1 | | using System.Text.Json; |
| | 2 | | using LGDXRobotCloud.API.Authorisation; |
| | 3 | | using LGDXRobotCloud.API.Configurations; |
| | 4 | | using LGDXRobotCloud.API.Services.Administration; |
| | 5 | | using LGDXRobotCloud.Data.Models.Business.Administration; |
| | 6 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Responses; |
| | 7 | | using LGDXRobotCloud.Utilities.Constants; |
| | 8 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | 9 | | using Microsoft.AspNetCore.Authorization; |
| | 10 | | using Microsoft.AspNetCore.Mvc; |
| | 11 | | using Microsoft.Extensions.Options; |
| | 12 | |
|
| | 13 | | namespace LGDXRobotCloud.API.Areas.Administration.Controllers; |
| | 14 | |
|
| | 15 | | [ApiController] |
| | 16 | | [Area("Administration")] |
| | 17 | | [Route("[area]/[controller]")] |
| | 18 | | [Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificateScheme)] |
| | 19 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| | 20 | | [ValidateLgdxUserAccess] |
| | 21 | |
|
| 0 | 22 | | public class ActivityLogsController( |
| 0 | 23 | | IActivityLogService activityLogService, |
| 0 | 24 | | IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration |
| 0 | 25 | | ) : ControllerBase |
| | 26 | | { |
| 0 | 27 | | private readonly IActivityLogService _activityLogService = activityLogService ?? throw new ArgumentNullException(nameo |
| 0 | 28 | | private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value ?? throw |
| | 29 | |
|
| | 30 | | [HttpGet("")] |
| | 31 | | [ProducesResponseType(typeof(IEnumerable<ActivityLogListDto>), StatusCodes.Status200OK)] |
| | 32 | | public async Task<ActionResult<IEnumerable<ActivityLogListDto>>> GetActivityLogs(string? entityName, string? entityId, |
| 0 | 33 | | { |
| 0 | 34 | | pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : |
| 0 | 35 | | var (activityLogs, PaginationHelper) = await _activityLogService.GetActivityLogsAsync(entityName, entityId, pageNumb |
| 0 | 36 | | Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper)); |
| 0 | 37 | | return Ok(activityLogs.ToDto()); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | [HttpGet("{id}", Name = "GetActivityLog")] |
| | 41 | | [ProducesResponseType(typeof(ActivityLogDto), StatusCodes.Status200OK)] |
| | 42 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | 43 | | public async Task<ActionResult<ActivityLogDto>> GetActivityLog(int id) |
| 0 | 44 | | { |
| 0 | 45 | | var activityLog = await _activityLogService.GetActivityLogAsync(id); |
| 0 | 46 | | return Ok(activityLog.ToDto()); |
| 0 | 47 | | } |
| | 48 | | } |