Handler.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. using Application.Abstractions.Cache;
  5. namespace Application.Features.Config.Get;
  6. public sealed class Handler(IAppDbContext db, ICacheService cache) : IQueryHandler<Query, Response?>
  7. {
  8. public async Task<Response?> Handle(Query request, CancellationToken ct)
  9. {
  10. var cached = await cache.GetAsync<Response>(CacheKeys.Config, ct);
  11. if (cached is not null)
  12. {
  13. return cached;
  14. }
  15. var config = await db.Config.AsNoTracking().OrderByDescending(x => x.ID).FirstOrDefaultAsync(ct);
  16. if (config is null)
  17. {
  18. return null;
  19. }
  20. var response = new Response
  21. {
  22. ID = config.ID,
  23. Basic = new Response.BasicConfigDto
  24. {
  25. SiteName = config.Basic.SiteName,
  26. SiteURL = config.Basic.SiteURL,
  27. RootID = config.Basic.RootID,
  28. FromEmail = config.Basic.FromEmail,
  29. FromName = config.Basic.FromName,
  30. SmtpServer = config.Basic.SmtpServer,
  31. SmtpPort = config.Basic.SmtpPort,
  32. SmtpEnableSSL = config.Basic.SmtpEnableSSL,
  33. SmtpUsername = config.Basic.SmtpUsername,
  34. SmtpPassword = config.Basic.SmtpPassword,
  35. AdminWhiteIPList = config.Basic.AdminWhiteIPList,
  36. FrontWhiteIPList = config.Basic.FrontWhiteIPList,
  37. BlockAlertTitle = config.Basic.BlockAlertTitle,
  38. BlockAlertContent = config.Basic.BlockAlertContent,
  39. IsMaintenance = config.Basic.IsMaintenance,
  40. MaintenanceContent = config.Basic.MaintenanceContent
  41. },
  42. Images = new Response.ImagesConfigDto
  43. {
  44. FaviconPath = config.Images.Favicon,
  45. LogoSquarePath = config.Images.LogoSquare,
  46. LogoHorizontalPath = config.Images.LogoHorizontal,
  47. OgDefaultPath = config.Images.OgDefault,
  48. TwitterImagePath = config.Images.TwitterImage,
  49. AppleTouchIconPath = config.Images.AppleTouchIcon,
  50. AppIcon192Path = config.Images.AppIcon_192,
  51. AppIcon512Path = config.Images.AppIcon_512
  52. },
  53. Meta = new Response.MetaConfigDto
  54. {
  55. Keywords = config.Meta.Keywords,
  56. Description = config.Meta.Description,
  57. Author = config.Meta.Author,
  58. Viewport = config.Meta.Viewport,
  59. ApplicationName = config.Meta.ApplicationName,
  60. Generator = config.Meta.Generator,
  61. Robots = config.Meta.Robots,
  62. Adds = config.Meta.Adds
  63. },
  64. Company = new Response.CompanyConfigDto
  65. {
  66. Name = config.Company.Name,
  67. RegNo = config.Company.RegNo,
  68. Address = config.Company.Address,
  69. ZipCode = config.Company.ZipCode,
  70. Owner = config.Company.Owner,
  71. Tel = config.Company.Tel,
  72. Fax = config.Company.Fax,
  73. RetailSaleNo = config.Company.RetailSaleNo,
  74. AddedSaleNo = config.Company.AddedSaleNo,
  75. Hosting = config.Company.Hosting,
  76. AdminName = config.Company.AdminName,
  77. AdminEmail = config.Company.AdminEmail,
  78. SiteUrl = config.Company.SiteUrl,
  79. BankCode = config.Company.BankCode,
  80. BankOwner = config.Company.BankOwner,
  81. BankNumber = config.Company.BankNumber
  82. },
  83. Account = new Response.AccountConfigDto
  84. {
  85. IsRegisterBlock = config.Account.IsRegisterBlock,
  86. IsRegisterEmailAuth = config.Account.IsRegisterEmailAuth,
  87. PasswordMinLength = config.Account.PasswordMinLength,
  88. PasswordUppercaseLength = config.Account.PasswordUppercaseLength,
  89. PasswordNumbersLength = config.Account.PasswordNumbersLength,
  90. PasswordSpecialcharsLength = config.Account.PasswordSpecialcharsLength,
  91. DeniedEmailList = config.Account.DeniedEmailList,
  92. DeniedNameList = config.Account.DeniedNameList,
  93. ChangeEmailDay = config.Account.ChangeEmailDay,
  94. ChangeNameDay = config.Account.ChangeNameDay,
  95. ChangeSummaryDay = config.Account.ChangeSummaryDay,
  96. ChangeIntroDay = config.Account.ChangeIntroDay,
  97. ChangePasswordDay = config.Account.ChangePasswordDay,
  98. IsLoginEmailVerifiedOnly = config.Account.IsLoginEmailVerifiedOnly,
  99. MaxLoginTryCount = config.Account.MaxLoginTryCount,
  100. MaxLoginTryLimitSecond = config.Account.MaxLoginTryLimitSecond
  101. },
  102. EmailTemplate = new Response.EmailTemplateConfigDto
  103. {
  104. RegisterEmailFormTitle = config.EmailTemplate.RegisterEmailFormTitle,
  105. RegisterEmailFormContent = config.EmailTemplate.RegisterEmailFormContent,
  106. RegistrationEmailFormTitle = config.EmailTemplate.RegistrationEmailFormTitle,
  107. RegistrationEmailFormContent = config.EmailTemplate.RegistrationEmailFormContent,
  108. ResetPasswordEmailFormTitle = config.EmailTemplate.ResetPasswordEmailFormTitle,
  109. ResetPasswordEmailFormContent = config.EmailTemplate.ResetPasswordEmailFormContent,
  110. ChangedPasswordEmailFormTitle = config.EmailTemplate.ChangedPasswordEmailFormTitle,
  111. ChangedPasswordEmailFormContent = config.EmailTemplate.ChangedPasswordEmailFormContent,
  112. WithdrawEmailFormTitle = config.EmailTemplate.WithdrawEmailFormTitle,
  113. WithdrawEmailFormContent = config.EmailTemplate.WithdrawEmailFormContent,
  114. EmailVerifyFormTitle = config.EmailTemplate.EmailVerifyFormTitle,
  115. EmailVerifyFormContent = config.EmailTemplate.EmailVerifyFormContent,
  116. ChangedEmailFormTitle = config.EmailTemplate.ChangedEmailFormTitle,
  117. ChangedEmailFormContent = config.EmailTemplate.ChangedEmailFormContent
  118. },
  119. External = new Response.ExternalApiConfigDto
  120. {
  121. YouTubeApiKeyEnc = config.External.YouTubeApiKeyEnc,
  122. YouTubeApiName = config.External.YouTubeApiName,
  123. GoogleClientId = config.External.GoogleClientId,
  124. GoogleClientSecretEnc = config.External.GoogleClientSecretEnc,
  125. GoogleAppId = config.External.GoogleAppId
  126. },
  127. Payment = new Response.PaymentConfigDto
  128. {
  129. }
  130. };
  131. await cache.SetAsync(CacheKeys.Config, response, ct);
  132. return response;
  133. }
  134. }