AccountConfigLoader.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Application.Abstractions.Cache;
  2. using Application.Abstractions.Data;
  3. using Application.Features.Config.Get;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Helpers;
  6. public static class AccountConfigLoader
  7. {
  8. /// <summary>
  9. /// Redis 캐시 → MSSQL 폴백으로 AccountConfigDto를 로드합니다.
  10. /// </summary>
  11. public static async Task<Response.AccountConfigDto> GetAccountConfigAsync(
  12. ICacheService cache, IAppDbContext db, CancellationToken ct)
  13. {
  14. // 1. Redis 캐시에서 조회
  15. var config = await cache.GetAsync<Response>(CacheKeys.Config, ct);
  16. if (config is not null)
  17. {
  18. return config.Account;
  19. }
  20. // 2. MSSQL 폴백
  21. var entity = await db.Config.AsNoTracking()
  22. .OrderByDescending(x => x.ID)
  23. .FirstOrDefaultAsync(ct);
  24. if (entity is null)
  25. {
  26. // Config가 없으면 기본값 반환
  27. return new Response.AccountConfigDto();
  28. }
  29. return new Response.AccountConfigDto
  30. {
  31. IsRegisterBlock = entity.Account.IsRegisterBlock,
  32. IsRegisterEmailAuth = entity.Account.IsRegisterEmailAuth,
  33. PasswordMinLength = entity.Account.PasswordMinLength,
  34. PasswordUppercaseLength = entity.Account.PasswordUppercaseLength,
  35. PasswordNumbersLength = entity.Account.PasswordNumbersLength,
  36. PasswordSpecialcharsLength = entity.Account.PasswordSpecialcharsLength,
  37. DeniedEmailList = entity.Account.DeniedEmailList,
  38. DeniedNameList = entity.Account.DeniedNameList,
  39. ChangeEmailDay = entity.Account.ChangeEmailDay,
  40. ChangeNameDay = entity.Account.ChangeNameDay,
  41. ChangeSummaryDay = entity.Account.ChangeSummaryDay,
  42. ChangeIntroDay = entity.Account.ChangeIntroDay,
  43. ChangePasswordDay = entity.Account.ChangePasswordDay,
  44. IsLoginEmailVerifiedOnly = entity.Account.IsLoginEmailVerifiedOnly,
  45. MaxLoginTryCount = entity.Account.MaxLoginTryCount,
  46. MaxLoginTryLimitSecond = entity.Account.MaxLoginTryLimitSecond
  47. };
  48. }
  49. }