using Aip.Service.Aip.Models; using Aip.Service.Models.Response; using Aip.Service.Repositories; using Aip.Service.Services.Interfaces; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.ComponentModel.DataAnnotations; namespace Aip.Service.Controllers; [ApiController] [Route("/api/v1/aip")] [Produces("application/json")] public class ApiAipController : BaseController { private readonly ILogger _log; private readonly IApiAipService _service; private readonly IApiAuthService _authService; public ApiAipController(ILogger log, IApiAuthService authService, IApiAipService apiAipService) { _log = log; _authService = authService; _service = apiAipService; } [HttpPost("download")] [SwaggerResponse(200, type: typeof(ApiResponseModel))] public async Task DownloadAipInfo([Required] string apiKey) { return await CreateResponseAsync(async () => { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_DOWNLOAD, apiKey, null); int authError = _authService.CheckApiKeyValidation(HttpContext, apiKey, GlobalConstants.API_AIP_DOWNLOAD); if (authError != 0) { throw ResponseApiKeyValidationError(HttpContext, authError); } var response = await _service.DownloadAipInfo(); var result = Results.Ok(ResponseSuccess(HttpContext, response)); HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } [HttpGet("labels")] [SwaggerResponse(200, type: typeof(ApiResponseModel>))] public async Task GetAipLabels([Required] string apiKey) { return await CreateResponseAsync(async () => { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_LABELS, apiKey, null); int authError = _authService.CheckApiKeyValidation(HttpContext, apiKey, GlobalConstants.API_AIP_LABELS); if (authError != 0) { throw ResponseApiKeyValidationError(HttpContext, authError); } var response = await _service.GetLabels(); var result = Results.Ok(new ApiResponseModel>() { success = true, errorCode = 0, errorMessage = GlobalConstants.API_RESULT_SUCCESS, result = response, }); HttpContext.Items[GlobalConstants.API_RESULT_CODE] = GlobalConstants.API_RESULT_SUCCESS_CODE; HttpContext.Items[GlobalConstants.API_RESULT_MESSAGE] = GlobalConstants.API_RESULT_SUCCESS; HttpContext.Items[GlobalConstants.API_RESULT] = response; return result; }); } [HttpGet("policies")] [SwaggerResponse(200, type: typeof(ApiResponseModel>))] public async Task GetAipPolicies([Required] string apiKey) { return await CreateResponseAsync(async () => { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_POLICIES, apiKey, null); int authError = _authService.CheckApiKeyValidation(HttpContext, apiKey, GlobalConstants.API_AIP_POLICIES); if (authError != 0) { throw ResponseApiKeyValidationError(HttpContext, authError); } var response = await _service.GetPolicies(); var result = Results.Ok(new ApiResponseModel>() { success = true, errorCode = 0, errorMessage = GlobalConstants.API_RESULT_SUCCESS, result = response, }); HttpContext.Items[GlobalConstants.API_RESULT_CODE] = GlobalConstants.API_RESULT_SUCCESS_CODE; HttpContext.Items[GlobalConstants.API_RESULT_MESSAGE] = GlobalConstants.API_RESULT_SUCCESS; HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } [HttpGet("protections")] [SwaggerResponse(200, type: typeof(ApiResponseModel>))] public async Task GetAipProtections([Required] string apiKey) { return await CreateResponseAsync(async () => { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_AIP_PROTECTIONS, apiKey, null); int authError = _authService.CheckApiKeyValidation(HttpContext, apiKey, GlobalConstants.API_AIP_PROTECTIONS); if (authError != 0) { throw ResponseApiKeyValidationError(HttpContext, authError); } var response = await _service.GetProtections(); var result = Results.Ok(new ApiResponseModel>() { success = true, errorCode = 0, errorMessage = GlobalConstants.API_RESULT_SUCCESS, result = response, }); HttpContext.Items[GlobalConstants.API_RESULT_CODE] = GlobalConstants.API_RESULT_SUCCESS_CODE; HttpContext.Items[GlobalConstants.API_RESULT_MESSAGE] = GlobalConstants.API_RESULT_SUCCESS; HttpContext.Items[GlobalConstants.API_RESULT] = result; return result; }); } }