using AipGateway.AIP; using AipGateway.API.Application.Modules; using AipGateway.API.Domain.IRepositories.IGenericRepositories; using AipGateway.API.Domain.Models; using AipGateway.API.Extensions; using AipGateway.API.Services; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; namespace AipGateway.API.Controllers { [ApiController] [Route("v1/aip-api/aip")] [Produces("application/json")] public class ApiAipController : BaseModule { private readonly ILogger _log; private readonly IApiAipService _apiAipService; public ApiAipController( ILogger logger, IUnitOfWork unitOfWork, IWebHostEnvironment webHostEnvironment, IApiAipService apiAipService) : base(unitOfWork, webHostEnvironment) { _log = logger; _apiAipService = apiAipService; _log.LogError("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: ApiAipController"); } [HttpPost("download")] [SwaggerResponse(200, type: typeof(SuccessResponseModel))] public async Task DownloadAipInfo(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_DOWNLOAD, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiAipService.DownloadAipInfo(); var result = Results.Ok(new SuccessResponseModel() { Message = GlobalConstants.API_RESULT_SUCCESS, Result = response, StatusCode = System.Net.HttpStatusCode.OK, Success = true }); HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } [HttpGet("labels")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetAipFileLabels(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_LABELS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiAipService.GetLabels(); var result = Results.Ok(new SuccessResponseModel>() { Message = GlobalConstants.API_RESULT_SUCCESS, Result = response, StatusCode = System.Net.HttpStatusCode.OK, Success = true }); HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } [HttpGet("policies")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetAipFilePolicies(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_POLICIES, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiAipService.GetPolicies(); var result = Results.Ok(new SuccessResponseModel>() { Message = GlobalConstants.API_RESULT_SUCCESS, Result = response, StatusCode = System.Net.HttpStatusCode.OK, Success = true }); HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } [HttpGet("protections")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetAipFileProtections(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_PROTECTIONS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiAipService.GetProtections(); var result = Results.Ok(new SuccessResponseModel>() { Message = GlobalConstants.API_RESULT_SUCCESS, Result = response, StatusCode = System.Net.HttpStatusCode.OK, Success = true }); HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } } }