| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using Application.Abstractions.Cache;
- using Application.Abstractions.Data;
- using Application.Features.Config.Get;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Helpers;
- public static class AccountConfigLoader
- {
- public static async Task<Response.EmailTemplateConfigDto> GetEmailTemplateAsync(
- ICacheService cache, IAppDbContext db, CancellationToken ct)
- {
- var config = await cache.GetAsync<Response>(CacheKeys.Config, ct);
- if (config is not null)
- {
- return config.EmailTemplate;
- }
- var entity = await db.Config.AsNoTracking().FirstOrDefaultAsync(ct);
- if (entity?.EmailTemplate is null)
- {
- return new Response.EmailTemplateConfigDto();
- }
- var e = entity.EmailTemplate;
- return new Response.EmailTemplateConfigDto
- {
- RegisterEmailFormTitle = e.RegisterEmailFormTitle,
- RegisterEmailFormContent = e.RegisterEmailFormContent,
- RegistrationEmailFormTitle = e.RegistrationEmailFormTitle,
- RegistrationEmailFormContent = e.RegistrationEmailFormContent,
- ResetPasswordEmailFormTitle = e.ResetPasswordEmailFormTitle,
- ResetPasswordEmailFormContent = e.ResetPasswordEmailFormContent,
- ChangedPasswordEmailFormTitle = e.ChangedPasswordEmailFormTitle,
- ChangedPasswordEmailFormContent = e.ChangedPasswordEmailFormContent,
- WithdrawEmailFormTitle = e.WithdrawEmailFormTitle,
- WithdrawEmailFormContent = e.WithdrawEmailFormContent,
- EmailVerifyFormTitle = e.EmailVerifyFormTitle,
- EmailVerifyFormContent = e.EmailVerifyFormContent,
- ChangedEmailFormTitle = e.ChangedEmailFormTitle,
- ChangedEmailFormContent = e.ChangedEmailFormContent
- };
- }
- /// <summary>
- /// Redis 캐시 → MSSQL 폴백으로 AccountConfigDto를 로드합니다.
- /// </summary>
- public static async Task<Response.AccountConfigDto> GetAccountConfigAsync(
- ICacheService cache, IAppDbContext db, CancellationToken ct)
- {
- // 1. Redis 캐시에서 조회
- var config = await cache.GetAsync<Response>(CacheKeys.Config, ct);
- if (config is not null)
- {
- return config.Account;
- }
- // 2. MSSQL 폴백
- var entity = await db.Config.AsNoTracking()
- .OrderByDescending(x => x.ID)
- .FirstOrDefaultAsync(ct);
- if (entity is null)
- {
- // Config가 없으면 기본값 반환
- return new Response.AccountConfigDto();
- }
- return new Response.AccountConfigDto
- {
- IsRegisterBlock = entity.Account.IsRegisterBlock,
- IsRegisterEmailAuth = entity.Account.IsRegisterEmailAuth,
- PasswordMinLength = entity.Account.PasswordMinLength,
- PasswordUppercaseLength = entity.Account.PasswordUppercaseLength,
- PasswordNumbersLength = entity.Account.PasswordNumbersLength,
- PasswordSpecialcharsLength = entity.Account.PasswordSpecialcharsLength,
- DeniedEmailList = entity.Account.DeniedEmailList,
- DeniedNameList = entity.Account.DeniedNameList,
- ChangeEmailDay = entity.Account.ChangeEmailDay,
- ChangeNameDay = entity.Account.ChangeNameDay,
- ChangeSummaryDay = entity.Account.ChangeSummaryDay,
- ChangeIntroDay = entity.Account.ChangeIntroDay,
- ChangeThumbDay = entity.Account.ChangeThumbDay,
- ChangePasswordDay = entity.Account.ChangePasswordDay,
- IsLoginEmailVerifiedOnly = entity.Account.IsLoginEmailVerifiedOnly,
- MaxLoginTryCount = entity.Account.MaxLoginTryCount,
- MaxLoginTryLimitSecond = entity.Account.MaxLoginTryLimitSecond
- };
- }
- }
|