Modified commands to use auth and current user
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Application.Authentication;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.User.Command.LogIn;
|
||||||
|
|
||||||
|
public record LogInUserCommand(string Email, string Password) : ICommand<Token>;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Application.Abstract.UserContext;
|
||||||
|
using AipsCore.Application.Authentication;
|
||||||
|
using AipsCore.Domain.Abstract;
|
||||||
|
using AipsCore.Domain.Models.User.External;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.User.Command.LogIn;
|
||||||
|
|
||||||
|
public class LogInUserCommandHandler : ICommandHandler<LogInUserCommand, Token>
|
||||||
|
{
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
private readonly ITokenProvider _tokenProvider;
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
|
public LogInUserCommandHandler(IUserRepository userRepository, ITokenProvider tokenProvider, IUnitOfWork unitOfWork)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
_tokenProvider = tokenProvider;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Token> Handle(LogInUserCommand command, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var loginResult = await _userRepository.LoginWithEmailAndPasswordAsync(command.Email, command.Password, cancellationToken);
|
||||||
|
|
||||||
|
return new Token(_tokenProvider.Generate(loginResult.User, loginResult.Roles));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Domain.Models.User.ValueObjects;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.User.Command.SignUp;
|
||||||
|
|
||||||
|
public record SignUpUserCommand(
|
||||||
|
string Username,
|
||||||
|
string Email,
|
||||||
|
string Password) : ICommand<UserId>;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Domain.Abstract;
|
||||||
|
using AipsCore.Domain.Models.User.External;
|
||||||
|
using AipsCore.Domain.Models.User.ValueObjects;
|
||||||
|
|
||||||
|
namespace AipsCore.Application.Models.User.Command.SignUp;
|
||||||
|
|
||||||
|
public class SignUpUserCommandHandler : ICommandHandler<SignUpUserCommand, UserId>
|
||||||
|
{
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
|
public SignUpUserCommandHandler(IUserRepository userRepository, IUnitOfWork unitOfWork)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserId> Handle(SignUpUserCommand command, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var user = Domain.Models.User.User.Create(command.Email, command.Username);
|
||||||
|
|
||||||
|
await _userRepository.SignUpWithPasswordAsync(user, command.Password, cancellationToken);
|
||||||
|
|
||||||
|
return user.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
|||||||
namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||||
|
|
||||||
public record CreateWhiteboardCommand(
|
public record CreateWhiteboardCommand(
|
||||||
string OwnerId,
|
|
||||||
string Title,
|
string Title,
|
||||||
int MaxParticipants,
|
int MaxParticipants,
|
||||||
WhiteboardJoinPolicy JoinPolicy)
|
WhiteboardJoinPolicy JoinPolicy)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using AipsCore.Application.Abstract.Command;
|
using AipsCore.Application.Abstract.Command;
|
||||||
|
using AipsCore.Application.Abstract.UserContext;
|
||||||
using AipsCore.Domain.Abstract;
|
using AipsCore.Domain.Abstract;
|
||||||
using AipsCore.Domain.Models.Whiteboard.External;
|
using AipsCore.Domain.Models.Whiteboard.External;
|
||||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
@@ -8,11 +9,13 @@ namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
|||||||
public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCommand, WhiteboardId>
|
public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCommand, WhiteboardId>
|
||||||
{
|
{
|
||||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||||
|
private readonly IUserContext _userContext;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
public CreateWhiteboardCommandHandler(IWhiteboardRepository whiteboardRepository, IUnitOfWork unitOfWork)
|
public CreateWhiteboardCommandHandler(IWhiteboardRepository whiteboardRepository, IUserContext userContext, IUnitOfWork unitOfWork)
|
||||||
{
|
{
|
||||||
_whiteboardRepository = whiteboardRepository;
|
_whiteboardRepository = whiteboardRepository;
|
||||||
|
_userContext = userContext;
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,8 +23,10 @@ public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCo
|
|||||||
{
|
{
|
||||||
var whiteboardCode = await WhiteboardCode.GenerateUniqueAsync(_whiteboardRepository);
|
var whiteboardCode = await WhiteboardCode.GenerateUniqueAsync(_whiteboardRepository);
|
||||||
|
|
||||||
|
var ownerId = _userContext.GetCurrentUserId();
|
||||||
|
|
||||||
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(
|
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(
|
||||||
command.OwnerId,
|
ownerId.IdValue,
|
||||||
whiteboardCode.CodeValue,
|
whiteboardCode.CodeValue,
|
||||||
command.Title,
|
command.Title,
|
||||||
command.MaxParticipants,
|
command.MaxParticipants,
|
||||||
|
|||||||
Reference in New Issue
Block a user