implement

This commit is contained in:
2026-02-09 21:21:17 +01:00
parent ff18d7b913
commit 2032a74ecd
14 changed files with 441 additions and 6 deletions

View File

@@ -0,0 +1,9 @@
using AipsCore.Domain.Models.Shape.ValueObjects;
namespace AipsCore.Domain.Models.Shape.External;
public interface IShapeRepository
{
Task<Shape?> Get(ShapeId id, CancellationToken cancellationToken = default);
Task Add(Shape shape, CancellationToken cancellationToken = default);
}

View File

@@ -7,7 +7,7 @@ namespace AipsCore.Domain.Models.Shape;
public abstract class Shape
{
public ShapeId Id { get; }
public ShapeId Id { get; init; }
public WhiteboardId WhiteboardId { get; private set; }
@@ -24,4 +24,16 @@ public abstract class Shape
Color = color;
WhiteboardId = whiteboardId;
}
protected Shape(
string id,
string whiteboardId,
int positionX, int positionY,
string color)
{
Id = new ShapeId(id);
Position = new Position(positionX, positionY);
Color = new Color(color);
WhiteboardId = new WhiteboardId(whiteboardId);
}
}

View File

@@ -17,4 +17,21 @@ public class Arrow : Shape
}
public override ShapeType ShapeType => ShapeType.Arrow;
public static Arrow Create(
string id,
string whiteboardId,
int positionX, int positionY,
string color,
int endPositionX, int endPositionY,
int borderThickness)
{
return new Arrow(
new ShapeId(id),
new WhiteboardId(whiteboardId),
new Position(positionX, positionY),
new Color(color),
new Position(endPositionX, endPositionY),
new Thickness(borderThickness));
}
}

View File

@@ -17,4 +17,21 @@ public class Line : Shape
}
public override ShapeType ShapeType => ShapeType.Line;
public static Line Create(
string id,
string whiteboardId,
int positionX, int positionY,
string color,
int endPositionX, int endPositionY,
int borderThickness)
{
return new Line(
new ShapeId(id),
new WhiteboardId(whiteboardId),
new Position(positionX, positionY),
new Color(color),
new Position(endPositionX, endPositionY),
new Thickness(borderThickness));
}
}

View File

@@ -20,4 +20,36 @@ public class Rectangle : Shape
BorderThickness = borderThickness;
}
public static Rectangle Create(
string id,
string whiteboardId,
int positionX, int positionY,
string color,
int endPositionX, int endPositionY,
int borderThickness)
{
return new Rectangle(
new ShapeId(id),
new WhiteboardId(whiteboardId),
new Position(positionX, positionY),
new Color(color),
new Position(endPositionX, endPositionY),
new Thickness(borderThickness));
}
public static Rectangle Create(
string whiteboardId,
int positionX, int positionY,
string color,
int endPositionX, int endPositionY,
int borderThickness)
{
return new Rectangle(
ShapeId.Any(),
new WhiteboardId(whiteboardId),
new Position(positionX, positionY),
new Color(color),
new Position(endPositionX, endPositionY),
new Thickness(borderThickness));
}
}

View File

@@ -20,4 +20,20 @@ public class TextShape : Shape
}
public override ShapeType ShapeType => ShapeType.Text;
public static TextShape Create(
string id,
string whiteboardId,
int positionX, int positionY,
string color,
string textValue, int textSize)
{
return new TextShape(
new ShapeId(id),
new WhiteboardId(whiteboardId),
new Position(positionX, positionY),
new Color(color),
new TextShapeValue(textValue),
new TextShapeSize(textSize));
}
}

View File

@@ -2,4 +2,7 @@ using AipsCore.Domain.Common.ValueObjects;
namespace AipsCore.Domain.Models.Shape.ValueObjects;
public record ShapeId(string Value) : DomainId(Value);
public record ShapeId(string Value) : DomainId(Value)
{
public static ShapeId Any() => new ShapeId(Guid.NewGuid().ToString());
}

View File

@@ -6,22 +6,23 @@ namespace AipsCore.Domain.Models.Shape.ValueObjects;
public record Thickness : AbstractValueObject
{
public int Value { get; }
private const int MaxThickness = 8;
private const int MinThickness = 1;
private readonly int _value;
public Thickness(int value)
{
_value = value;
Value = value;
Validate();
}
protected override ICollection<IRule> GetValidationRules()
{
return
[
new MinValueRule<int>(_value, MinThickness),
new MaxValueRule<int>(_value, MaxThickness),
new MinValueRule<int>(Value, MinThickness),
new MaxValueRule<int>(Value, MaxThickness),
];
}
}