Merge pull request #27 from StewKI/hotfix-create-rectangle
Hotfix create rectangle
This commit is contained in:
@@ -1,24 +1,37 @@
|
|||||||
using AipsCore.Application.Abstract.Command;
|
using AipsCore.Application.Abstract.Command;
|
||||||
using AipsCore.Domain.Abstract;
|
using AipsCore.Domain.Abstract;
|
||||||
|
using AipsCore.Domain.Common.Validation;
|
||||||
using AipsCore.Domain.Models.Shape.External;
|
using AipsCore.Domain.Models.Shape.External;
|
||||||
using AipsCore.Domain.Models.Shape.Sub.Rectangle;
|
using AipsCore.Domain.Models.Shape.Sub.Rectangle;
|
||||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||||
|
using AipsCore.Domain.Models.User.External;
|
||||||
|
using AipsCore.Domain.Models.User.Validation;
|
||||||
|
using AipsCore.Domain.Models.User.ValueObjects;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.External;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.Validation;
|
||||||
|
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||||
|
|
||||||
namespace AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
namespace AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||||
|
|
||||||
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand, ShapeId>
|
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand, ShapeId>
|
||||||
{
|
{
|
||||||
private readonly IShapeRepository _shapeRepository;
|
private readonly IShapeRepository _shapeRepository;
|
||||||
|
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
|
||||||
public CreateRectangleCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork)
|
public CreateRectangleCommandHandler(IShapeRepository shapeRepository, IWhiteboardRepository whiteboardRepository, IUserRepository userRepository, IUnitOfWork unitOfWork)
|
||||||
{
|
{
|
||||||
_shapeRepository = shapeRepository;
|
_shapeRepository = shapeRepository;
|
||||||
|
_whiteboardRepository = whiteboardRepository;
|
||||||
|
_userRepository = userRepository;
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ShapeId> Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
public async Task<ShapeId> Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
Validate(command);
|
||||||
|
|
||||||
var rectangle = Rectangle.Create(
|
var rectangle = Rectangle.Create(
|
||||||
command.WhiteboardId,
|
command.WhiteboardId,
|
||||||
command.AuthorId,
|
command.AuthorId,
|
||||||
@@ -33,4 +46,23 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
|||||||
|
|
||||||
return rectangle.Id;
|
return rectangle.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Validate(CreateRectangleCommand command)
|
||||||
|
{
|
||||||
|
var whiteboardId = new WhiteboardId(command.WhiteboardId);
|
||||||
|
var whiteboard = _whiteboardRepository.GetByIdAsync(whiteboardId).Result;
|
||||||
|
|
||||||
|
if (whiteboard is null)
|
||||||
|
{
|
||||||
|
throw new ValidationException(WhiteboardErrors.NotFound(whiteboardId));
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorId = new UserId(command.AuthorId);
|
||||||
|
var author = _userRepository.GetByIdAsync(authorId).Result;
|
||||||
|
|
||||||
|
if (author is null)
|
||||||
|
{
|
||||||
|
throw new ValidationException(UserErrors.NotFound(authorId));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using AipsCore.Application.Abstract;
|
using AipsCore.Application.Abstract;
|
||||||
|
using AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||||
using AipsCore.Application.Models.Shape.Command.CreateArrow;
|
using AipsCore.Application.Models.Shape.Command.CreateArrow;
|
||||||
using AipsCore.Application.Models.Shape.Command.CreateLine;
|
using AipsCore.Application.Models.Shape.Command.CreateLine;
|
||||||
using AipsCore.Application.Models.Shape.Command.CreateTextShape;
|
using AipsCore.Application.Models.Shape.Command.CreateTextShape;
|
||||||
|
|||||||
Reference in New Issue
Block a user