implement
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user