123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- 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<ApiDbController> _log;
- private readonly IApiDbService _apiDbService;
- public ApiDbController(
- ILogger<ApiDbController> 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<ApiResponseDto>))]
- public async Task<IResult> 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<ApiResponseDto>()
- {
- 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<List<LinkedSystemDto>>))]
- public async Task<IResult> 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<List<LinkedSystemDto>>()
- {
- 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<List<LinkedServerDto>>))]
- public async Task<IResult> 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<List<LinkedServerDto>>()
- {
- 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<List<LinkedApiKeyDto>>))]
- public async Task<IResult> 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<List<LinkedApiKeyDto>>()
- {
- 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<List<LinkedDecryptKeyDto>>))]
- public async Task<IResult> 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<List<LinkedDecryptKeyDto>>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- });
- HttpContext.Items[GlobalConstants.API_RESULT] = result;
- return result;
- });
- }
- }
- }
|