using Application.Abstractions.Data; using Application.Abstractions.Messaging; using SharedKernel; using SharedKernel.Results; using Microsoft.EntityFrameworkCore; namespace Application.Features.Api.Crew.ToggleWidgetActive; internal sealed class Handler(IAppDbContext db) : ICommandHandler> { public async Task> Handle(Command r, CancellationToken ct) { var config = await db.CrewWidgetConfig .FirstOrDefaultAsync(c => c.ID == r.ID && c.ChannelID == r.ChannelID, ct); if (config is null) { return Result.Failure(Error.NotFound("CrewWidgetConfig.NotFound", "위젯 설정을 찾을 수 없습니다.")); } if (config.IsActive == r.IsActive) { return Result.Success(new Response(config.ID, config.IsActive)); } config.SetActive(r.IsActive); await db.SaveChangesAsync(ct); return Result.Success(new Response(config.ID, config.IsActive)); } }