This commit is contained in:
Veljko Tosic
2026-02-12 09:51:09 +01:00
parent b0f5f38412
commit aa012d2b0c
11 changed files with 245 additions and 0 deletions

View File

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

View File

@@ -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<CreateArrowCommand, ShapeId>
{
private readonly IShapeRepository _shapeRepository;
private readonly IUnitOfWork _unitOfWork;
public CreateArrowCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork)
{
_shapeRepository = shapeRepository;
_unitOfWork = unitOfWork;
}
public async Task<ShapeId> 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;
}
}

View File

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

View File

@@ -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<CreateLineCommand, ShapeId>
{
private readonly IShapeRepository _shapeRepository;
private readonly IUnitOfWork _unitOfWork;
public CreateLineCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork)
{
_shapeRepository = shapeRepository;
_unitOfWork = unitOfWork;
}
public async Task<ShapeId> 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;
}
}

View File

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

View File

@@ -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<CreateTextShapeCommand, ShapeId>
{
private readonly IShapeRepository _shapeRepository;
private readonly IUnitOfWork _unitOfWork;
public CreateTextShapeCommandHandler(IShapeRepository shapeRepository, IUnitOfWork unitOfWork)
{
_shapeRepository = shapeRepository;
_unitOfWork = unitOfWork;
}
public async Task<ShapeId> 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;
}
}

View File

@@ -38,4 +38,22 @@ public class Arrow : Shape
new Position(endPositionX, endPositionY), new Position(endPositionX, endPositionY),
new Thickness(borderThickness)); 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));
}
} }

View File

@@ -38,4 +38,22 @@ public class Line : Shape
new Position(endPositionX, endPositionY), new Position(endPositionX, endPositionY),
new Thickness(borderThickness)); 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));
}
} }

View File

@@ -39,4 +39,21 @@ public class TextShape : Shape
new TextShapeValue(textValue), new TextShapeValue(textValue),
new TextShapeSize(textSize)); 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));
}
} }

View File

@@ -28,6 +28,7 @@ public static partial class ShapeMappers
Id = new Guid(rectangle.Id.Value), Id = new Guid(rectangle.Id.Value),
Type = rectangle.ShapeType, Type = rectangle.ShapeType,
WhiteboardId = new Guid(rectangle.WhiteboardId.IdValue), WhiteboardId = new Guid(rectangle.WhiteboardId.IdValue),
AuthorId = new Guid(rectangle.AuthorId.IdValue),
PositionX = rectangle.Position.X, PositionX = rectangle.Position.X,
PositionY = rectangle.Position.Y, PositionY = rectangle.Position.Y,
Color = rectangle.Color.Value, Color = rectangle.Color.Value,
@@ -45,6 +46,7 @@ public static partial class ShapeMappers
Id = new Guid(line.Id.Value), Id = new Guid(line.Id.Value),
Type = line.ShapeType, Type = line.ShapeType,
WhiteboardId = new Guid(line.WhiteboardId.IdValue), WhiteboardId = new Guid(line.WhiteboardId.IdValue),
AuthorId = new Guid(line.AuthorId.IdValue),
PositionX = line.Position.X, PositionX = line.Position.X,
PositionY = line.Position.Y, PositionY = line.Position.Y,
Color = line.Color.Value, Color = line.Color.Value,
@@ -62,6 +64,7 @@ public static partial class ShapeMappers
Id = new Guid(arrow.Id.Value), Id = new Guid(arrow.Id.Value),
Type = arrow.ShapeType, Type = arrow.ShapeType,
WhiteboardId = new Guid(arrow.WhiteboardId.IdValue), WhiteboardId = new Guid(arrow.WhiteboardId.IdValue),
AuthorId = new Guid(arrow.AuthorId.IdValue),
PositionX = arrow.Position.X, PositionX = arrow.Position.X,
PositionY = arrow.Position.Y, PositionY = arrow.Position.Y,
Color = arrow.Color.Value, Color = arrow.Color.Value,
@@ -79,6 +82,7 @@ public static partial class ShapeMappers
Id = new Guid(textShape.Id.Value), Id = new Guid(textShape.Id.Value),
Type = textShape.ShapeType, Type = textShape.ShapeType,
WhiteboardId = new Guid(textShape.WhiteboardId.IdValue), WhiteboardId = new Guid(textShape.WhiteboardId.IdValue),
AuthorId = new Guid(textShape.AuthorId.IdValue),
PositionX = textShape.Position.X, PositionX = textShape.Position.X,
PositionY = textShape.Position.Y, PositionY = textShape.Position.Y,
Color = textShape.Color.Value, Color = textShape.Color.Value,

View File

@@ -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<IActionResult> CreateArrow(CreateArrowCommand command, CancellationToken cancellationToken)
{
var result = await _dispatcher.Execute(command, cancellationToken);
return Ok(result);
}
[HttpPost("textShape")]
public async Task<IActionResult> CreateTextShape(CreateTextShapeCommand command, CancellationToken cancellationToken)
{
var result = await _dispatcher.Execute(command, cancellationToken);
return Ok(result);
}
[HttpPost("line")]
public async Task<IActionResult> CreateLine(CreateLineCommand command, CancellationToken cancellationToken)
{
var result = await _dispatcher.Execute(command, cancellationToken);
return Ok(result);
}
}