| 1234567891011121314151617181920212223242526272829 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- using SharedKernel.Results;
- namespace Application.Features.Api.ChannelTitle.DeleteChannelTitle;
- internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result>
- {
- public async Task<Result> Handle(Command request, CancellationToken ct)
- {
- var title = await db.ChannelTitle.Include(t => t.Channel).FirstOrDefaultAsync(t => t.ID == request.TitleID, ct);
- if (title is null)
- {
- return Result.Failure(Error.NotFound("ChannelTitle.NotFound", "칭호를 찾을 수 없습니다."));
- }
- if (title.Channel is null || title.Channel.MemberID != request.MemberID)
- {
- return Result.Failure(Error.Forbidden("ChannelTitle.Forbidden", "본인 채널의 칭호만 삭제할 수 있습니다."));
- }
- // 관련 선택 기록의 참조는 SetNull FK로 자동 처리됨
- db.ChannelTitle.Remove(title);
- await db.SaveChangesAsync(ct);
- return Result.Success();
- }
- }
|