diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommand.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommand.cs new file mode 100644 index 0000000..cf96853 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommand.cs @@ -0,0 +1,14 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateArrow; + +public record CreateArrowCommand( + string WhiteboardId, + string AuthorId, + int PositionX, + int PositionY, + string Color, + int EndPositionX, + int EndPositionY, + int Thickness) : ICommand; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommandHandler.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommandHandler.cs new file mode 100644 index 0000000..80de92a --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateArrow/CreateArrowCommandHandler.cs @@ -0,0 +1,35 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Abstract; +using AipsCore.Domain.Models.Shape.External; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateArrow; + +public class CreateArrowCommandHandler : ICommandHandler +{ + private readonly IShapeRepository _shapeRepository; + private readonly IUnitOfWork _unitOfWork; + + public CreateArrowCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork) + { + _shapeRepository = shapeRepository; + _unitOfWork = unitOfWork; + } + + public async Task Handle(CreateArrowCommand command, CancellationToken cancellationToken = default) + { + var arrow = Domain.Models.Shape.Sub.Arrow.Arrow.Create( + command.WhiteboardId, + command.AuthorId, + command.PositionX, command.PositionY, + command.Color, + command.EndPositionX, + command.EndPositionY, + command.Thickness); + + await _shapeRepository.SaveAsync(arrow, cancellationToken); + await _unitOfWork.SaveChangesAsync(cancellationToken); + + return arrow.Id; + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommand.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommand.cs new file mode 100644 index 0000000..b901e87 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommand.cs @@ -0,0 +1,14 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateLine; + +public record CreateLineCommand( + string WhiteboardId, + string AuthorId, + int PositionX, + int PositionY, + string Color, + int EndPositionX, + int EndPositionY, + int Thickness) : ICommand; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommandHandler.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommandHandler.cs new file mode 100644 index 0000000..c2338bd --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateLine/CreateLineCommandHandler.cs @@ -0,0 +1,36 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Abstract; +using AipsCore.Domain.Models.Shape.External; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateLine; + +public class CreateLineCommandHandler : ICommandHandler +{ + private readonly IShapeRepository _shapeRepository; + private readonly IUnitOfWork _unitOfWork; + + public CreateLineCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork) + { + _shapeRepository = shapeRepository; + _unitOfWork = unitOfWork; + } + + public async Task Handle(CreateLineCommand command, CancellationToken cancellationToken = default) + { + var line = Domain.Models.Shape.Sub.Line.Line.Create( + command.WhiteboardId, + command.AuthorId, + command.PositionX, + command.PositionY, + command.Color, + command.EndPositionX, + command.EndPositionY, + command.Thickness); + + await _shapeRepository.SaveAsync(line, cancellationToken); + await _unitOfWork.SaveChangesAsync(cancellationToken); + + return line.Id; + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommand.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommand.cs new file mode 100644 index 0000000..4fa716a --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommand.cs @@ -0,0 +1,13 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateTextShape; + +public record CreateTextShapeCommand( + string WhiteboardId, + string AuthorId, + int PositionX, + int PositionY, + string Color, + string Text, + int TextSize) : ICommand; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommandHandler.cs b/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommandHandler.cs new file mode 100644 index 0000000..a024423 --- /dev/null +++ b/dotnet/AipsCore/Application/Models/Shape/Command/CreateTextShape/CreateTextShapeCommandHandler.cs @@ -0,0 +1,36 @@ +using AipsCore.Application.Abstract.Command; +using AipsCore.Domain.Abstract; +using AipsCore.Domain.Models.Shape.External; +using AipsCore.Domain.Models.Shape.Sub.TextShape; +using AipsCore.Domain.Models.Shape.ValueObjects; + +namespace AipsCore.Application.Models.Shape.Command.CreateTextShape; + +public class CreateTextShapeCommandHandler : ICommandHandler +{ + private readonly IShapeRepository _shapeRepository; + private readonly IUnitOfWork _unitOfWork; + + public CreateTextShapeCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork) + { + _shapeRepository = shapeRepository; + _unitOfWork = unitOfWork; + } + + public async Task Handle(CreateTextShapeCommand command, CancellationToken cancellationToken = default) + { + var textShape = TextShape.Create( + command.WhiteboardId, + command.AuthorId, + command.PositionX, + command.PositionY, + command.Color, + command.Text, + command.TextSize); + + await _shapeRepository.SaveAsync(textShape, cancellationToken); + await _unitOfWork.SaveChangesAsync(cancellationToken); + + return textShape.Id; + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.cs b/dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.cs index f53e9ad..e28b7a4 100644 --- a/dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.cs +++ b/dotnet/AipsCore/Domain/Models/Shape/Sub/Arrow/Arrow.cs @@ -38,4 +38,22 @@ public class Arrow : Shape new Position(endPositionX, endPositionY), new Thickness(borderThickness)); } + + public static Arrow Create( + string whiteboardId, + string authorId, + int positionX, int positionY, + string color, + int endPositionX, int endPositionY, + int borderThickness) + { + return new Arrow( + ShapeId.Any(), + new WhiteboardId(whiteboardId), + new UserId(authorId), + new Position(positionX, positionY), + new Color(color), + new Position(endPositionX, endPositionY), + new Thickness(borderThickness)); + } } \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.cs b/dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.cs index 06af1fb..204810c 100644 --- a/dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.cs +++ b/dotnet/AipsCore/Domain/Models/Shape/Sub/Line/Line.cs @@ -38,4 +38,22 @@ public class Line : Shape new Position(endPositionX, endPositionY), new Thickness(borderThickness)); } + + public static Line Create( + string whiteboardId, + string authorId, + int positionX, int positionY, + string color, + int endPositionX, int endPositionY, + int borderThickness) + { + return new Line( + ShapeId.Any(), + new WhiteboardId(whiteboardId), + new UserId(authorId), + new Position(positionX, positionY), + new Color(color), + new Position(endPositionX, endPositionY), + new Thickness(borderThickness)); + } } \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Models/Shape/Sub/TextShape/TextShape.cs b/dotnet/AipsCore/Domain/Models/Shape/Sub/TextShape/TextShape.cs index 3d7578f..5bc8062 100644 --- a/dotnet/AipsCore/Domain/Models/Shape/Sub/TextShape/TextShape.cs +++ b/dotnet/AipsCore/Domain/Models/Shape/Sub/TextShape/TextShape.cs @@ -39,4 +39,21 @@ public class TextShape : Shape new TextShapeValue(textValue), new TextShapeSize(textSize)); } + + public static TextShape Create( + string whiteboardId, + string authorId, + int positionX, int positionY, + string color, + string textValue, int textSize) + { + return new TextShape( + ShapeId.Any(), + new WhiteboardId(whiteboardId), + new UserId(authorId), + new Position(positionX, positionY), + new Color(color), + new TextShapeValue(textValue), + new TextShapeSize(textSize)); + } } \ No newline at end of file diff --git a/dotnet/AipsCore/Infrastructure/Persistence/Shape/Mappers/ShapeMappers.ToEntity.cs b/dotnet/AipsCore/Infrastructure/Persistence/Shape/Mappers/ShapeMappers.ToEntity.cs index 6275364..f4b228a 100644 --- a/dotnet/AipsCore/Infrastructure/Persistence/Shape/Mappers/ShapeMappers.ToEntity.cs +++ b/dotnet/AipsCore/Infrastructure/Persistence/Shape/Mappers/ShapeMappers.ToEntity.cs @@ -28,6 +28,7 @@ public static partial class ShapeMappers Id = new Guid(rectangle.Id.Value), Type = rectangle.ShapeType, WhiteboardId = new Guid(rectangle.WhiteboardId.IdValue), + AuthorId = new Guid(rectangle.AuthorId.IdValue), PositionX = rectangle.Position.X, PositionY = rectangle.Position.Y, Color = rectangle.Color.Value, @@ -45,6 +46,7 @@ public static partial class ShapeMappers Id = new Guid(line.Id.Value), Type = line.ShapeType, WhiteboardId = new Guid(line.WhiteboardId.IdValue), + AuthorId = new Guid(line.AuthorId.IdValue), PositionX = line.Position.X, PositionY = line.Position.Y, Color = line.Color.Value, @@ -62,6 +64,7 @@ public static partial class ShapeMappers Id = new Guid(arrow.Id.Value), Type = arrow.ShapeType, WhiteboardId = new Guid(arrow.WhiteboardId.IdValue), + AuthorId = new Guid(arrow.AuthorId.IdValue), PositionX = arrow.Position.X, PositionY = arrow.Position.Y, Color = arrow.Color.Value, @@ -79,6 +82,7 @@ public static partial class ShapeMappers Id = new Guid(textShape.Id.Value), Type = textShape.ShapeType, WhiteboardId = new Guid(textShape.WhiteboardId.IdValue), + AuthorId = new Guid(textShape.AuthorId.IdValue), PositionX = textShape.Position.X, PositionY = textShape.Position.Y, Color = textShape.Color.Value, diff --git a/dotnet/AipsWebApi/Controllers/ShapeController.cs b/dotnet/AipsWebApi/Controllers/ShapeController.cs new file mode 100644 index 0000000..47e47d9 --- /dev/null +++ b/dotnet/AipsWebApi/Controllers/ShapeController.cs @@ -0,0 +1,40 @@ +using AipsCore.Application.Abstract; +using AipsCore.Application.Models.Shape.Command.CreateArrow; +using AipsCore.Application.Models.Shape.Command.CreateLine; +using AipsCore.Application.Models.Shape.Command.CreateTextShape; +using Microsoft.AspNetCore.Mvc; + +namespace AipsWebApi.Controllers; + +[ApiController] +[Route("[controller]")] +public class ShapeController : ControllerBase +{ + private readonly IDispatcher _dispatcher; + + public ShapeController(IDispatcher dispatcher) + { + _dispatcher = dispatcher; + } + + [HttpPost("arrow")] + public async Task CreateArrow(CreateArrowCommand command, CancellationToken cancellationToken) + { + var result = await _dispatcher.Execute(command, cancellationToken); + return Ok(result); + } + + [HttpPost("textShape")] + public async Task CreateTextShape(CreateTextShapeCommand command, CancellationToken cancellationToken) + { + var result = await _dispatcher.Execute(command, cancellationToken); + return Ok(result); + } + + [HttpPost("line")] + public async Task CreateLine(CreateLineCommand command, CancellationToken cancellationToken) + { + var result = await _dispatcher.Execute(command, cancellationToken); + return Ok(result); + } +} \ No newline at end of file