using Application.Abstractions.Messaging; using Application.Abstractions.Data; using Microsoft.EntityFrameworkCore; using SharedKernel.Results; namespace Application.Features.Api.Forum.Comment.Update; public sealed class Handler(IAppDbContext db) : ICommandHandler { public async Task Handle(Command request, CancellationToken ct) { if (string.IsNullOrWhiteSpace(request.Content)) { return Result.Failure(Error.Problem("Comment.ContentRequired", "내용을 입력해주세요.")); } var comment = await db.Comment.FirstOrDefaultAsync(x => x.ID == request.ID, ct); if (comment is null) { return Result.Failure(Error.NotFound("Comment.NotFound", "댓글을 찾을 수 없습니다.")); } if (comment.MemberID != request.MemberID) { return Result.Failure(Error.Forbidden("Comment.Forbidden", "수정 권한이 없습니다.")); } comment.Content = request.Content.Trim(); comment.IsSecret = request.IsSecret; comment.UpdatedAt = DateTime.UtcNow; await db.SaveChangesAsync(ct); return Result.Success(); } }