Merge branch 'main' into hotfix-create-rectangle
# Conflicts: # dotnet/AipsWebApi/Controllers/ShapeController.cs
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
|
||||
namespace AipsCore.Application.Abstract.UserContext;
|
||||
|
||||
public interface ITokenProvider
|
||||
{
|
||||
string Generate(User user, IList<UserRole> roles);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public interface IAuthService
|
||||
{
|
||||
Task SignUpWithPasswordAsync(User user, string password, CancellationToken cancellationToken = default);
|
||||
Task<LoginResult> LoginWithEmailAndPasswordAsync(string email, string password, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public record LoginResult(User User, IList<UserRole> Roles);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public record Token(string Value);
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Common.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.Common.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 IAuthService _authService;
|
||||
|
||||
public LogInUserCommandHandler(IUserRepository userRepository, ITokenProvider tokenProvider, IAuthService authService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_tokenProvider = tokenProvider;
|
||||
_authService = authService;
|
||||
}
|
||||
|
||||
public async Task<Token> Handle(LogInUserCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var loginResult = await _authService.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,28 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Common.Authentication;
|
||||
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 IAuthService _authService;
|
||||
|
||||
public SignUpUserCommandHandler(IUserRepository userRepository, IAuthService authService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_authService = authService;
|
||||
}
|
||||
|
||||
public async Task<UserId> Handle(SignUpUserCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = Domain.Models.User.User.Create(command.Email, command.Username);
|
||||
|
||||
await _authService.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;
|
||||
|
||||
public record CreateWhiteboardCommand(
|
||||
string OwnerId,
|
||||
string Title,
|
||||
int MaxParticipants,
|
||||
WhiteboardJoinPolicy JoinPolicy)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Abstract.UserContext;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.Whiteboard.External;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
@@ -8,20 +9,24 @@ namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||
public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCommand, WhiteboardId>
|
||||
{
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
private readonly IUserContext _userContext;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateWhiteboardCommandHandler(IWhiteboardRepository whiteboardRepository, IUnitOfWork unitOfWork)
|
||||
|
||||
public CreateWhiteboardCommandHandler(IWhiteboardRepository whiteboardRepository, IUserContext userContext, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_whiteboardRepository = whiteboardRepository;
|
||||
_userContext = userContext;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<WhiteboardId> Handle(CreateWhiteboardCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardCode = await WhiteboardCode.GenerateUniqueAsync(_whiteboardRepository);
|
||||
|
||||
var ownerId = _userContext.GetCurrentUserId();
|
||||
|
||||
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(
|
||||
command.OwnerId,
|
||||
ownerId.IdValue,
|
||||
whiteboardCode.CodeValue,
|
||||
command.Title,
|
||||
command.MaxParticipants,
|
||||
|
||||
Reference in New Issue
Block a user