ApiDbService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using AipGateway.API.Application.Modules;
  2. using AipGateway.API.Domain.Entities;
  3. using AipGateway.API.Domain.IRepositories.IGenericRepositories;
  4. using AipGateway.API.Domain.Models;
  5. using AutoMapper;
  6. namespace AipGateway.API.Services.impl
  7. {
  8. public class ApiDbService : IApiDbService
  9. {
  10. private readonly ILogger<ApiFileService> _log;
  11. private readonly IServiceProvider _provider;
  12. private readonly IUnitOfWork _unitOfWork;
  13. private readonly IMapper _mapper;
  14. public ApiDbService(ILogger<ApiFileService> logger, IServiceProvider provider, IUnitOfWork unitOfWork, IMapper mapper)
  15. {
  16. _log = logger;
  17. _provider = provider;
  18. _unitOfWork = unitOfWork;
  19. _mapper = mapper;
  20. _log.LogError("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: ApiDbService");
  21. }
  22. public async Task<ApiResponseDto> ReloadDatabase()
  23. {
  24. try
  25. {
  26. //AipFileApiService? aipFileApiService = ContainerService.provider.GetService<AipFileApiService>();
  27. AipFileApiService? aipFileApiService = _provider.GetService<AipFileApiService>();
  28. if (aipFileApiService == null)
  29. {
  30. return new ApiResponseDto
  31. {
  32. errorCode = 1,
  33. errorMessage = "AIP File 관리 서비스를 찾을 수 없습니다.",
  34. effectCount = 0,
  35. };
  36. }
  37. var task = Task.Run(() =>
  38. {
  39. aipFileApiService.LoadLinkedApiKeys();
  40. aipFileApiService.LoadLinkedDecryptKeys();
  41. return ContainerService.apiKeyMap.Count + ContainerService.decryptKeyMap.Count;
  42. });
  43. int result = await task;
  44. return new ApiResponseDto
  45. {
  46. errorCode = 0,
  47. errorMessage = GlobalConstants.API_RESULT_SUCCESS,
  48. effectCount = result,
  49. };
  50. }
  51. catch (Exception)
  52. {
  53. throw;
  54. }
  55. }
  56. public async Task<List<LinkedSystemDto>> GetLinkedSystems()
  57. {
  58. try
  59. {
  60. var result = await _unitOfWork.LinkedSystemRepository.GetAllAsync();
  61. return _mapper.Map<List<LinkedSystemDto>>(result);
  62. }
  63. catch (Exception)
  64. {
  65. throw;
  66. }
  67. }
  68. public async Task<List<LinkedServerDto>> GetLinkedServers()
  69. {
  70. try
  71. {
  72. var result = await _unitOfWork.LinkedServerRepository.GetAllAsync();
  73. return _mapper.Map<List<LinkedServerDto>>(result);
  74. }
  75. catch (Exception)
  76. {
  77. throw;
  78. }
  79. }
  80. public async Task<List<LinkedApiKeyDto>> GetLinkedApiKeys()
  81. {
  82. try
  83. {
  84. var result = await _unitOfWork.LinkedApiKeyRepository.GetAllAsync();
  85. return _mapper.Map<List<LinkedApiKeyDto>>(result);
  86. }
  87. catch (Exception)
  88. {
  89. throw;
  90. }
  91. }
  92. public async Task<List<LinkedDecryptKeyDto>> GetLinkedDecryptKeys()
  93. {
  94. try
  95. {
  96. var result = await _unitOfWork.LinkedDecryptKeyRepository.GetAllAsync();
  97. return _mapper.Map<List<LinkedDecryptKeyDto>>(result);
  98. }
  99. catch (Exception)
  100. {
  101. throw;
  102. }
  103. }
  104. }
  105. }