implement

This commit is contained in:
2026-02-17 00:48:28 +01:00
parent 0119c7a737
commit 5c7909034f
57 changed files with 1676 additions and 114 deletions

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);
}
}