using AipGateway.API.Application.Modules; using AipGateway.API.Domain.Entities; 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/db")] [Produces("application/json")] public class ApiDbController : BaseModule { private readonly ILogger _log; private readonly IApiDbService _apiDbService; public ApiDbController( ILogger logger, IUnitOfWork unitOfWork, IWebHostEnvironment webHostEnvironment, IApiDbService apiDbService) : base(unitOfWork, webHostEnvironment) { _log = logger; _apiDbService = apiDbService; _log.LogError("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: ApiDbController"); } [HttpPost("reload")] [SwaggerResponse(200, type: typeof(SuccessResponseModel))] public async Task ReloadDatabase(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DB_RELOAD, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiDbService.ReloadDatabase(); 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("linked-systems")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetLinkedSystems(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DB_LINKED_SYSTEMS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiDbService.GetLinkedSystems(); 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("linked-servers")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetLinkedServers(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DB_LINKED_SERVERS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiDbService.GetLinkedServers(); 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("linked-api-keys")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetLinkedApiKeys(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DB_LINKED_API_KEYS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiDbService.GetLinkedApiKeys(); 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("linked-decrypt-keys")] [SwaggerResponse(200, type: typeof(SuccessResponseModel>))] public async Task GetLinkedDecryptKeys(string apiKey) { GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_DB_LINKED_DECRYPT_KEYS, apiKey); return await CreateResponseAsync(async () => { int authError = ContainerService.ValidationApiAuthorization(HttpContext, apiKey); if (authError != 0) { throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError); } var response = await _apiDbService.GetLinkedDecryptKeys(); 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; }); } } }