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 GetEmailTemplateAsync( ICacheService cache, IAppDbContext db, CancellationToken ct) { var config = await cache.GetAsync(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 }; } /// /// Redis 캐시 → MSSQL 폴백으로 AccountConfigDto를 로드합니다. /// public static async Task GetAccountConfigAsync( ICacheService cache, IAppDbContext db, CancellationToken ct) { // 1. Redis 캐시에서 조회 var config = await cache.GetAsync(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 }; } }