Canceling join request now actually changes the status to cancelled so trying to join same RequestToJoin whiteboard with code manually doesnt fail due to status being Pending
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.UserCanceledRequestToJoin;
|
||||
|
||||
public record UserCanceledRequestToJoinCommand(string WhiteboardId, string UserId): ICommand;
|
||||
@@ -0,0 +1,40 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.Enums;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.Validation;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.UserCanceledRequestToJoin;
|
||||
|
||||
public class CancelJoinRequestCommandHandler : ICommandHandler<UserCanceledRequestToJoinCommand>
|
||||
{
|
||||
private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CancelJoinRequestCommandHandler(IWhiteboardMembershipRepository whiteboardMembershipRepository, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_whiteboardMembershipRepository = whiteboardMembershipRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task Handle(UserCanceledRequestToJoinCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardId = new WhiteboardId(command.WhiteboardId);
|
||||
var userId = new UserId(command.UserId);
|
||||
|
||||
var membership = await _whiteboardMembershipRepository.GetByWhiteboardAndUserAsync(whiteboardId, userId, cancellationToken);
|
||||
|
||||
if (membership is null)
|
||||
{
|
||||
throw new ValidationException(WhiteboardMembershipErrors.NotFound(whiteboardId, userId));
|
||||
}
|
||||
|
||||
membership.UpdateStatus(WhiteboardMembershipStatus.Cancelled);
|
||||
|
||||
await _whiteboardMembershipRepository.SaveAsync(membership, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user