Merge branch 'main' into feature-whiteboard-query-getall
# Conflicts: # dotnet/AipsWebApi/Controllers/WhiteboardController.cs
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Abstract.UserContext;
|
||||
|
||||
public interface IUserContext
|
||||
{
|
||||
UserId GetCurrentUserId();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.BanUserFromWhiteboard;
|
||||
|
||||
public record BanUserFromWhiteboardCommand(string UserId, string WhiteboardId) : ICommand;
|
||||
@@ -0,0 +1,18 @@
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.BanUserFromWhiteboard;
|
||||
|
||||
public static class BanUserFromWhiteboardCommandErrors
|
||||
{
|
||||
public static ValidationError WhiteboardMembershipNotFound(WhiteboardId whiteboardId, UserId userId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_membership_not_found",
|
||||
Message: $"User with id '{userId.IdValue}' is not a member of whiteboard with id '{whiteboardId.IdValue}'");
|
||||
|
||||
public static ValidationError WhiteboardNotFound(WhiteboardId whiteboardId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_not_found",
|
||||
Message: $"Whiteboard with id '{whiteboardId.IdValue}' not found.");
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Abstract.UserContext;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.External;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.BanUserFromWhiteboard;
|
||||
|
||||
public class BanUserFromWhiteboardCommandHandler : ICommandHandler<BanUserFromWhiteboardCommand>
|
||||
{
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository;
|
||||
private readonly IUserContext _userContext;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public BanUserFromWhiteboardCommandHandler(
|
||||
IWhiteboardRepository whiteboardRepository,
|
||||
IWhiteboardMembershipRepository whiteboardMembershipRepository,
|
||||
IUserContext userContext,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_whiteboardMembershipRepository = whiteboardMembershipRepository;
|
||||
_userContext = userContext;
|
||||
_unitOfWork = unitOfWork;
|
||||
_whiteboardRepository = whiteboardRepository;
|
||||
}
|
||||
|
||||
public async Task Handle(BanUserFromWhiteboardCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardId = new WhiteboardId(command.WhiteboardId);
|
||||
var userId = new UserId(command.UserId);
|
||||
|
||||
var whiteboard = await _whiteboardRepository.GetByIdAsync(whiteboardId, cancellationToken);
|
||||
|
||||
if (whiteboard is null)
|
||||
{
|
||||
throw new ValidationException(BanUserFromWhiteboardCommandErrors.WhiteboardNotFound(whiteboardId));
|
||||
}
|
||||
|
||||
var membership = await _whiteboardMembershipRepository.GetByWhiteboardAndUserAsync(whiteboardId, userId, cancellationToken);
|
||||
|
||||
if (membership is null)
|
||||
{
|
||||
throw new ValidationException(BanUserFromWhiteboardCommandErrors.WhiteboardMembershipNotFound(whiteboardId, userId));
|
||||
}
|
||||
|
||||
whiteboard.BanUser(_userContext.GetCurrentUserId(), membership);
|
||||
|
||||
await _whiteboardMembershipRepository.SaveAsync(membership, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.KickUserFromWhiteboard;
|
||||
|
||||
public record KickUserFromWhiteboardCommand(string UserId, string WhiteboardId) : ICommand;
|
||||
@@ -0,0 +1,18 @@
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.KickUserFromWhiteboard;
|
||||
|
||||
public static class KickUserFromWhiteboardCommandErrors
|
||||
{
|
||||
public static ValidationError WhiteboardMembershipNotFound(WhiteboardId whiteboardId, UserId userId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_membership_not_found",
|
||||
Message: $"User with id '{userId}' is not a member of whiteboard with id '{whiteboardId}'");
|
||||
|
||||
public static ValidationError WhiteboardNotFound(WhiteboardId whiteboardId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_not_found",
|
||||
Message: $"Whiteboard with id '{whiteboardId}' not found.");
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Abstract.UserContext;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.External;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.KickUserFromWhiteboard;
|
||||
|
||||
public class KickUserFromWhiteboardCommandHandler : ICommandHandler<KickUserFromWhiteboardCommand>
|
||||
{
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository;
|
||||
private readonly IUserContext _userContext;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public KickUserFromWhiteboardCommandHandler(
|
||||
IWhiteboardRepository whiteboardRepository,
|
||||
IWhiteboardMembershipRepository whiteboardMembershipRepository,
|
||||
IUserContext userContext,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_whiteboardMembershipRepository = whiteboardMembershipRepository;
|
||||
_userContext = userContext;
|
||||
_unitOfWork = unitOfWork;
|
||||
_whiteboardRepository = whiteboardRepository;
|
||||
}
|
||||
|
||||
public async Task Handle(KickUserFromWhiteboardCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardId = new WhiteboardId(command.WhiteboardId);
|
||||
var userId = new UserId(command.UserId);
|
||||
|
||||
var whiteboard = await _whiteboardRepository.GetByIdAsync(whiteboardId, cancellationToken);
|
||||
|
||||
if (whiteboard is null)
|
||||
{
|
||||
throw new ValidationException(KickUserFromWhiteboardCommandErrors.WhiteboardNotFound(whiteboardId));
|
||||
}
|
||||
|
||||
var membership = await _whiteboardMembershipRepository.GetByWhiteboardAndUserAsync(whiteboardId, userId, cancellationToken);
|
||||
|
||||
if (membership is null)
|
||||
{
|
||||
throw new ValidationException(KickUserFromWhiteboardCommandErrors.WhiteboardMembershipNotFound(whiteboardId, userId));
|
||||
}
|
||||
|
||||
whiteboard.KickUser(_userContext.GetCurrentUserId(), membership);
|
||||
|
||||
await _whiteboardMembershipRepository.SaveAsync(membership, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.UnbanUserFromWhiteboard;
|
||||
|
||||
public record UnbanUserFromWhiteboardCommand(string UserId, string WhiteboardId) : ICommand;
|
||||
@@ -0,0 +1,18 @@
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.UnbanUserFromWhiteboard;
|
||||
|
||||
public static class UnbanUserFromWhiteboardCommandErrors
|
||||
{
|
||||
public static ValidationError WhiteboardMembershipNotFound(WhiteboardId whiteboardId, UserId userId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_membership_not_found",
|
||||
Message: $"User with id '{userId}' is not a member of whiteboard with id '{whiteboardId}'");
|
||||
|
||||
public static ValidationError WhiteboardNotFound(WhiteboardId whiteboardId)
|
||||
=> new ValidationError(
|
||||
Code: "whiteboard_not_found",
|
||||
Message: $"Whiteboard with id '{whiteboardId}' not found.");
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Abstract.UserContext;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.External;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.UnbanUserFromWhiteboard;
|
||||
|
||||
public class UnbanUserFromWhiteboardCommandHandler : ICommandHandler<UnbanUserFromWhiteboardCommand>
|
||||
{
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
private readonly IWhiteboardMembershipRepository _whiteboardMembershipRepository;
|
||||
private readonly IUserContext _userContext;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public UnbanUserFromWhiteboardCommandHandler(
|
||||
IWhiteboardRepository whiteboardRepository,
|
||||
IWhiteboardMembershipRepository whiteboardMembershipRepository,
|
||||
IUserContext userContext,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_whiteboardRepository = whiteboardRepository;
|
||||
_whiteboardMembershipRepository = whiteboardMembershipRepository;
|
||||
_userContext = userContext;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task Handle(UnbanUserFromWhiteboardCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardId = new WhiteboardId(command.WhiteboardId);
|
||||
var userId = new UserId(command.UserId);
|
||||
|
||||
var whiteboard = await _whiteboardRepository.GetByIdAsync(whiteboardId, cancellationToken);
|
||||
|
||||
if (whiteboard is null)
|
||||
{
|
||||
throw new ValidationException(UnbanUserFromWhiteboardCommandErrors.WhiteboardNotFound(whiteboardId));
|
||||
}
|
||||
|
||||
var membership = await _whiteboardMembershipRepository.GetByWhiteboardAndUserAsync(whiteboardId, userId, cancellationToken);
|
||||
|
||||
if (membership is null)
|
||||
{
|
||||
throw new ValidationException(UnbanUserFromWhiteboardCommandErrors.WhiteboardMembershipNotFound(whiteboardId, userId));
|
||||
}
|
||||
|
||||
whiteboard.UnbanUser(_userContext.GetCurrentUserId(), membership);
|
||||
|
||||
await _whiteboardMembershipRepository.SaveAsync(membership, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user