Merge branch 'main' into hotfix-create-rectangle

# Conflicts:
#	dotnet/AipsWebApi/Controllers/ShapeController.cs
This commit is contained in:
2026-02-12 09:52:55 +01:00
11 changed files with 228 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

@@ -46,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,
@@ -63,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,
@@ -80,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

@@ -1,5 +1,8 @@
using AipsCore.Application.Abstract; using AipsCore.Application.Abstract;
using AipsCore.Application.Models.Shape.Command.CreateRectangle; using AipsCore.Application.Models.Shape.Command.CreateRectangle;
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; using Microsoft.AspNetCore.Mvc;
namespace AipsWebApi.Controllers; namespace AipsWebApi.Controllers;
@@ -21,4 +24,25 @@ public class ShapeController : ControllerBase
var result = await _dispatcher.Execute(command, token); var result = await _dispatcher.Execute(command, token);
return Ok(result); return Ok(result);
} }
[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);
}
} }