From 3a40657b1d642329e62cf53d676d4bdb34d2ce6b Mon Sep 17 00:00:00 2001 From: Jonas Seiler Date: Thu, 3 Apr 2025 11:01:53 +0200 Subject: [PATCH] Domain: Add Street Entity --- src/Domain/Street.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Domain/Street.cs diff --git a/src/Domain/Street.cs b/src/Domain/Street.cs new file mode 100644 index 0000000..479cb7d --- /dev/null +++ b/src/Domain/Street.cs @@ -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()); + } +} \ No newline at end of file