| 12345678910111213141516171819202122232425262728 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using SharedKernel.Results;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Api.DonationRemote.MarkDelivered;
- internal sealed class Handler(IAppDbContext db) : ICommandHandler<Command, Result<Response>>
- {
- public async Task<Result<Response>> Handle(Command r, CancellationToken ct)
- {
- var alert = await db.DonationAlert.Include(a => a.Donation).ThenInclude(d => d!.Channel).FirstOrDefaultAsync(a => a.ID == r.AlertID, ct);
- if (alert is null || alert.Donation is null || alert.Donation.Channel is null)
- {
- return Result.Failure<Response>(Error.NotFound("DonationAlert.NotFound", "알림을 찾을 수 없습니다."));
- }
- if (alert.Donation.Channel.MemberID != r.RequesterMemberID)
- {
- return Result.Failure<Response>(Error.Forbidden("Remote.Forbidden", "권한이 없습니다."));
- }
- alert.MarkDelivered();
- await db.SaveChangesAsync(ct);
- return Result.Success(new Response(alert.ID, alert.Donation.Channel.WidgetToken!));
- }
- }
|