| 12345678910111213141516171819202122232425262728293031 |
- 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<Command, Result<Response>>
- {
- public async Task<Result<Response>> 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<Response>(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));
- }
- }
|