ApiDbService.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using AipGateway.API.Application;
  2. using AipGateway.API.Application.Interfaces.Services;
  3. using AipGateway.API.Domain.Exceptions;
  4. using AipGateway.API.Domain.IRepositories.IGenericRepositories;
  5. using AipGateway.API.Domain.Models.Dto;
  6. using AipGateway.API.Domain.Models.Response;
  7. using AipGateway.API.Repositories;
  8. using AipGateway.API.Services.Interfaces;
  9. using AutoMapper;
  10. namespace AipGateway.API.Services
  11. {
  12. public class ApiDbService : BaseService, IApiDbService
  13. {
  14. private readonly ILogger<ApiDbService> _log;
  15. private readonly IApiAuthService _apiAuthService;
  16. private readonly IAipDbRepository _repo;
  17. public ApiDbService(ILogger<ApiDbService> log, IAipFileService aipFileService, IApiAuthService apiAuthService, IAipDbRepository repo)
  18. : base(aipFileService)
  19. {
  20. _log = log;
  21. _apiAuthService = apiAuthService;
  22. _repo = repo;
  23. }
  24. public async Task<GeneralResponse> ReloadDatabase()
  25. {
  26. try
  27. {
  28. var task = Task.Run(() =>
  29. {
  30. int result = _apiAuthService.LoadAuthInformation();
  31. return result;
  32. });
  33. int result = await task;
  34. return new GeneralResponse
  35. {
  36. errorCode = 0,
  37. errorMessage = GlobalConstants.API_RESULT_SUCCESS,
  38. effectCount = result,
  39. };
  40. }
  41. catch (Exception)
  42. {
  43. throw;
  44. }
  45. }
  46. public async Task<List<LinkedSystemDto>> GetLinkedSystems()
  47. {
  48. try
  49. {
  50. var result = await _repo.GetLinkedSystems();
  51. return result;
  52. }
  53. catch (Exception)
  54. {
  55. throw;
  56. }
  57. }
  58. public async Task<List<LinkedServerDto>> GetLinkedServers()
  59. {
  60. try
  61. {
  62. var result = await _repo.GetLinkedServers();
  63. return result;
  64. }
  65. catch (Exception)
  66. {
  67. throw;
  68. }
  69. }
  70. public async Task<List<LinkedApiKeyDto>> GetLinkedApiKeys()
  71. {
  72. try
  73. {
  74. var result = await _repo.GetLinkedApiKeys();
  75. return result;
  76. }
  77. catch (Exception)
  78. {
  79. throw;
  80. }
  81. }
  82. public async Task<List<LinkedDecryptKeyDto>> GetLinkedDecryptKeys()
  83. {
  84. try
  85. {
  86. var result = await _repo.GetLinkedDecryptKeys();
  87. return result;
  88. }
  89. catch (Exception)
  90. {
  91. throw;
  92. }
  93. }
  94. }
  95. }