async process on worker of AddRectangle
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddRectangle;
|
||||
|
||||
public record AddRectangleMessage(CreateRectangleCommand Command) : IMessage;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddRectangle;
|
||||
|
||||
public class AddRectangleMessageHandler : IMessageHandler<AddRectangleMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public AddRectangleMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(AddRectangleMessage 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.CreateRectangle;
|
||||
|
||||
public record CreateRectangleCommand(
|
||||
string Id,
|
||||
string WhiteboardId,
|
||||
string AuthorId,
|
||||
int PositionX,
|
||||
@@ -11,4 +12,4 @@ public record CreateRectangleCommand(
|
||||
string Color,
|
||||
int EndPositionX,
|
||||
int EndPositionY,
|
||||
int BorderThickness) : ICommand<ShapeId>;
|
||||
int BorderThickness) : ICommand;
|
||||
@@ -13,7 +13,7 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
|
||||
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand, ShapeId>
|
||||
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
@@ -28,11 +28,12 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<ShapeId> Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Validate(command);
|
||||
|
||||
var rectangle = Rectangle.Create(
|
||||
command.Id,
|
||||
command.WhiteboardId,
|
||||
command.AuthorId,
|
||||
command.PositionX, command.PositionY,
|
||||
@@ -43,8 +44,6 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
||||
|
||||
await _shapeRepository.SaveAsync(rectangle, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return rectangle.Id;
|
||||
}
|
||||
|
||||
private void Validate(CreateRectangleCommand command)
|
||||
|
||||
@@ -30,6 +30,7 @@ public class RabbitMqSubscriber : IMessageSubscriber
|
||||
|
||||
await channel.QueueDeclareAsync(
|
||||
queue: GetQueueName<T>(),
|
||||
autoDelete: false,
|
||||
durable: true);
|
||||
|
||||
await channel.QueueBindAsync(
|
||||
|
||||
Reference in New Issue
Block a user