using Application.Abstractions.Cache; using Application.Abstractions.Data; using Application.Abstractions.Messaging; using Domain.Entities.Common; using Microsoft.EntityFrameworkCore; namespace Application.Features.Admin.Channel.ExpConfig.Update; internal sealed class Handler(IAppDbContext db, ICacheService cache) : ICommandHandler { public async Task Handle(Command request, CancellationToken ct) { var entity = await db.Config .OrderByDescending(x => x.ID) .FirstOrDefaultAsync(ct); if (entity is null) { entity = Domain.Entities.Common.Config.Create(); await db.Config.AddAsync(entity, ct); } var chatExp = new ChatExpConfig { ChatXpPerMessage = request.ChatXpPerMessage, DonationXpPerAmount = request.DonationXpPerAmount, ChatXpSessionLimit = request.ChatXpSessionLimit, MinContentLength = request.MinContentLength, RateLimitSec = request.RateLimitSec, LeaderboardSize = request.LeaderboardSize, CrownTopN = request.CrownTopN, UxShowLeaderboard = request.UxShowLeaderboard, UxShowMyXpBadge = request.UxShowMyXpBadge }; entity.UpdateChatExp(chatExp); await db.SaveChangesAsync(ct); // 캐시 무효화 await cache.RemoveAsync(CacheKeys.Config, ct); } }