implement
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Application\Models\Shape\Command\DeleteShape\" />
|
||||
<Folder Include="Domain\Models\WhiteboardMembership\Validation\" />
|
||||
<Folder Include="Infrastructure\Persistence\Db\Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateArrow;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddArrow;
|
||||
|
||||
public record AddArrowMessage(CreateArrowCommand Command) : IMessage;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddArrow;
|
||||
|
||||
public class AddArrowMessageHandler : IMessageHandler<AddArrowMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public AddArrowMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(AddArrowMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _dispatcher.Execute(message.Command, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateLine;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddLine;
|
||||
|
||||
public record AddLineMessage(CreateLineCommand Command) : IMessage;
|
||||
@@ -0,0 +1,20 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateLine;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddLine;
|
||||
|
||||
public class AddLineMessageHandler : IMessageHandler<AddLineMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public AddLineMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(AddLineMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _dispatcher.Execute(message.Command, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateTextShape;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddTextShape;
|
||||
|
||||
public record AddTextShapeMessage(CreateTextShapeCommand Command) : IMessage;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddTextShape;
|
||||
|
||||
public class AddTextShapeMessageHandler : IMessageHandler<AddTextShapeMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public AddTextShapeMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(AddTextShapeMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _dispatcher.Execute(message.Command, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.MoveShape;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.MoveShape;
|
||||
|
||||
public record MoveShapeMessage(MoveShapeCommand Command) : IMessage;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.MoveShape;
|
||||
|
||||
public class MoveShapeMessageHandler : IMessageHandler<MoveShapeMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public MoveShapeMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(MoveShapeMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _dispatcher.Execute(message.Command, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateArrow;
|
||||
|
||||
public record CreateArrowCommand(
|
||||
string Id,
|
||||
string WhiteboardId,
|
||||
string AuthorId,
|
||||
int PositionX,
|
||||
@@ -11,4 +12,4 @@ public record CreateArrowCommand(
|
||||
string Color,
|
||||
int EndPositionX,
|
||||
int EndPositionY,
|
||||
int Thickness) : ICommand<ShapeId>;
|
||||
int Thickness) : ICommand;
|
||||
@@ -5,7 +5,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateArrow;
|
||||
|
||||
public class CreateArrowCommandHandler : ICommandHandler<CreateArrowCommand, ShapeId>
|
||||
public class CreateArrowCommandHandler : ICommandHandler<CreateArrowCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
@@ -16,9 +16,10 @@ public class CreateArrowCommandHandler : ICommandHandler<CreateArrowCommand, Sha
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<ShapeId> Handle(CreateArrowCommand command, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(CreateArrowCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var arrow = Domain.Models.Shape.Sub.Arrow.Arrow.Create(
|
||||
command.Id,
|
||||
command.WhiteboardId,
|
||||
command.AuthorId,
|
||||
command.PositionX, command.PositionY,
|
||||
@@ -28,8 +29,6 @@ public class CreateArrowCommandHandler : ICommandHandler<CreateArrowCommand, Sha
|
||||
command.Thickness);
|
||||
|
||||
await _shapeRepository.SaveAsync(arrow, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return arrow.Id;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateLine;
|
||||
|
||||
public record CreateLineCommand(
|
||||
string Id,
|
||||
string WhiteboardId,
|
||||
string AuthorId,
|
||||
int PositionX,
|
||||
@@ -11,4 +12,4 @@ public record CreateLineCommand(
|
||||
string Color,
|
||||
int EndPositionX,
|
||||
int EndPositionY,
|
||||
int Thickness) : ICommand<ShapeId>;
|
||||
int Thickness) : ICommand;
|
||||
@@ -5,7 +5,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateLine;
|
||||
|
||||
public class CreateLineCommandHandler : ICommandHandler<CreateLineCommand, ShapeId>
|
||||
public class CreateLineCommandHandler : ICommandHandler<CreateLineCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
@@ -16,9 +16,10 @@ public class CreateLineCommandHandler : ICommandHandler<CreateLineCommand, Shape
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<ShapeId> Handle(CreateLineCommand command, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(CreateLineCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var line = Domain.Models.Shape.Sub.Line.Line.Create(
|
||||
command.Id,
|
||||
command.WhiteboardId,
|
||||
command.AuthorId,
|
||||
command.PositionX,
|
||||
@@ -30,7 +31,5 @@ public class CreateLineCommandHandler : ICommandHandler<CreateLineCommand, Shape
|
||||
|
||||
await _shapeRepository.SaveAsync(line, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return line.Id;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,11 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateTextShape;
|
||||
|
||||
public record CreateTextShapeCommand(
|
||||
string Id,
|
||||
string WhiteboardId,
|
||||
string AuthorId,
|
||||
int PositionX,
|
||||
int PositionY,
|
||||
string Color,
|
||||
string Text,
|
||||
int TextSize) : ICommand<ShapeId>;
|
||||
int TextSize) : ICommand;
|
||||
@@ -6,7 +6,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateTextShape;
|
||||
|
||||
public class CreateTextShapeCommandHandler : ICommandHandler<CreateTextShapeCommand, ShapeId>
|
||||
public class CreateTextShapeCommandHandler : ICommandHandler<CreateTextShapeCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
@@ -17,9 +17,10 @@ public class CreateTextShapeCommandHandler : ICommandHandler<CreateTextShapeComm
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<ShapeId> Handle(CreateTextShapeCommand command, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(CreateTextShapeCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var textShape = TextShape.Create(
|
||||
command.Id,
|
||||
command.WhiteboardId,
|
||||
command.AuthorId,
|
||||
command.PositionX,
|
||||
@@ -30,7 +31,5 @@ public class CreateTextShapeCommandHandler : ICommandHandler<CreateTextShapeComm
|
||||
|
||||
await _shapeRepository.SaveAsync(textShape, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return textShape.Id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.MoveShape;
|
||||
|
||||
public record MoveShapeCommand(string ShapeId, int NewPositionX, int NewPositionY) : ICommand;
|
||||
@@ -0,0 +1,36 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.Shape.External;
|
||||
using AipsCore.Domain.Models.Shape.Validation;
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.MoveShape;
|
||||
|
||||
public class MoveShapeCommandHandler : ICommandHandler<MoveShapeCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public MoveShapeCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_shapeRepository = shapeRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task Handle(MoveShapeCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var id = new ShapeId(command.ShapeId);
|
||||
var shape = await _shapeRepository.GetByIdAsync(id, cancellationToken);
|
||||
|
||||
if (shape == null)
|
||||
{
|
||||
throw new ValidationException(ShapeErrors.NotFound(id));
|
||||
}
|
||||
|
||||
shape.Move(command.NewPositionX, command.NewPositionY);
|
||||
|
||||
await _shapeRepository.SaveAsync(shape, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
13
dotnet/AipsCore/Domain/Models/Shape/Shape.Move.cs
Normal file
13
dotnet/AipsCore/Domain/Models/Shape/Shape.Move.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape;
|
||||
|
||||
public partial class Shape
|
||||
{
|
||||
public virtual void Move(int newPositionX, int newPositionY)
|
||||
{
|
||||
var newPosition = new Position(newPositionX, newPositionY);
|
||||
|
||||
this.Position = newPosition;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape;
|
||||
|
||||
public abstract class Shape : DomainModel<ShapeId>
|
||||
public abstract partial class Shape : DomainModel<ShapeId>
|
||||
{
|
||||
public WhiteboardId WhiteboardId { get; private set; }
|
||||
|
||||
|
||||
11
dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.Move.cs
Normal file
11
dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.Move.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Arrow;
|
||||
|
||||
public partial class Arrow
|
||||
{
|
||||
public override void Move(int newPositionX, int newPositionY)
|
||||
{
|
||||
EndPosition.X += newPositionX - Position.X;
|
||||
EndPosition.Y += newPositionY - Position.Y;
|
||||
base.Move(newPositionX, newPositionY);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Arrow;
|
||||
|
||||
public class Arrow : Shape
|
||||
public partial class Arrow : Shape
|
||||
{
|
||||
public Position EndPosition { get; private set; }
|
||||
public Thickness Thickness { get; private set; }
|
||||
|
||||
11
dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.Move.cs
Normal file
11
dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.Move.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Line;
|
||||
|
||||
public partial class Line
|
||||
{
|
||||
public override void Move(int newPositionX, int newPositionY)
|
||||
{
|
||||
EndPosition.X += newPositionX - Position.X;
|
||||
EndPosition.Y += newPositionY - Position.Y;
|
||||
base.Move(newPositionX, newPositionY);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Line;
|
||||
|
||||
public class Line : Shape
|
||||
public partial class Line : Shape
|
||||
{
|
||||
public Position EndPosition { get; private set; }
|
||||
public Thickness Thickness { get; private set; }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Rectangle;
|
||||
|
||||
public partial class Rectangle
|
||||
{
|
||||
public override void Move(int newPositionX, int newPositionY)
|
||||
{
|
||||
EndPosition.X += newPositionX - Position.X;
|
||||
EndPosition.Y += newPositionY - Position.Y;
|
||||
base.Move(newPositionX, newPositionY);
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape.Sub.Rectangle;
|
||||
|
||||
public class Rectangle : Shape
|
||||
public partial class Rectangle : Shape
|
||||
{
|
||||
public override ShapeType ShapeType => ShapeType.Rectangle;
|
||||
|
||||
public Position EndPosition { get; }
|
||||
public Position EndPosition { get; set; }
|
||||
|
||||
public Thickness BorderThickness { get; }
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using AipsCore.Domain.Abstract.Validation;
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape.Validation;
|
||||
|
||||
public class ShapeErrors : AbstractErrors<Shape, ShapeId>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ namespace AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
public record Position : AbstractValueObject
|
||||
{
|
||||
public int X { get; }
|
||||
public int Y { get; }
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public Position(int x, int y)
|
||||
{
|
||||
@@ -20,4 +20,14 @@ public record Position : AbstractValueObject
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public static Position operator -(Position position, Position otherPosition)
|
||||
{
|
||||
return new Position(position.X - otherPosition.X, position.Y - otherPosition.Y);
|
||||
}
|
||||
|
||||
public static Position operator +(Position position, Position otherPosition)
|
||||
{
|
||||
return new Position(position.X + otherPosition.X, position.Y + otherPosition.Y);
|
||||
}
|
||||
};
|
||||
@@ -25,6 +25,7 @@ public static partial class ShapeMappers
|
||||
return Rectangle.Create(
|
||||
shape.Id.ToString(),
|
||||
shape.WhiteboardId.ToString(),
|
||||
shape.AuthorId.ToString(),
|
||||
shape.PositionX, shape.PositionY,
|
||||
shape.Color,
|
||||
shape.EndPositionX!.Value, shape.EndPositionY!.Value,
|
||||
|
||||
Reference in New Issue
Block a user