Domain: Add Street Entity

This commit is contained in:
Jonas Seiler 2025-04-03 11:01:53 +02:00
parent 90df1edf75
commit 3a40657b1d

50
src/Domain/Street.cs Normal file
View File

@ -0,0 +1,50 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using NetTopologySuite.Geometries;
public class Street
{
public string Name { get; private set; }
public int Capacity { get; private set; }
// Could be changed to a more general geometry type instead of the implementation specific LineString
public LineString Geometry { get; private set; }
[Timestamp]
public uint Version { get; set; }
public Street(string name, int capacity, LineString geometry)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Street name cannot be empty.", nameof(name));
}
if (capacity <= 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be positive.");
}
if (geometry == null || geometry.IsEmpty)
{
throw new ArgumentException("Geometry cannot be null or empty.", nameof(geometry));
}
Name = name;
Capacity = capacity;
Geometry = geometry;
}
public void AddPointToGeometry(Coordinate point, bool atEnd = true)
{
if (point == null)
{
throw new ArgumentNullException(nameof(point), "Point cannot be null.");
}
var coords = Geometry.Coordinates.ToList();
coords.Add(point);
Geometry = new LineString(coords.ToArray());
}
}