mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 09:41:15 +00:00
f7ad7aa5ab
Extract RouteValidator (aggregating validator), RoutePointGraphBuilder (point interpolation + sequence numbering), GeofenceGridCalculator (NW/SE region centers), and RouteResponseMapper (entity -> DTO; also used by GetRouteAsync, eliminating duplicate DTO assembly). CreateRouteAsync shrinks 184 -> 52 LOC of orchestration. RouteService.cs shrinks 295 -> 138 LOC overall. Validation aggregates all failures into a single ArgumentException (AC-2); single-violation messages preserved verbatim so existing RouteServiceTests pass unchanged. 28 new unit tests for the four helpers (112/112 unit tests, smoke green). Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using SatelliteProvider.Common.DTO;
|
|
|
|
namespace SatelliteProvider.Services.RouteManagement;
|
|
|
|
public class RouteValidator
|
|
{
|
|
public void Validate(CreateRouteRequest request)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(request);
|
|
|
|
var errors = new List<string>();
|
|
|
|
if (request.Points is null || request.Points.Count < 2)
|
|
{
|
|
errors.Add("Route must have at least 2 points");
|
|
}
|
|
|
|
if (request.RegionSizeMeters < 100 || request.RegionSizeMeters > 10000)
|
|
{
|
|
errors.Add("Region size must be between 100 and 10000 meters");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(request.Name))
|
|
{
|
|
errors.Add("Route name is required");
|
|
}
|
|
|
|
if (request.Geofences?.Polygons is { Count: > 0 } polygons)
|
|
{
|
|
for (int i = 0; i < polygons.Count; i++)
|
|
{
|
|
ValidatePolygon(polygons[i], errors);
|
|
}
|
|
}
|
|
|
|
if (errors.Count > 0)
|
|
{
|
|
throw new ArgumentException(string.Join("; ", errors));
|
|
}
|
|
}
|
|
|
|
private static void ValidatePolygon(GeofencePolygon polygon, List<string> errors)
|
|
{
|
|
if (polygon.NorthWest is null || polygon.SouthEast is null)
|
|
{
|
|
errors.Add("Geofence polygon coordinates are required");
|
|
return;
|
|
}
|
|
|
|
var nw = polygon.NorthWest;
|
|
var se = polygon.SouthEast;
|
|
|
|
if ((Math.Abs(nw.Lat) < 0.0001 && Math.Abs(nw.Lon) < 0.0001) ||
|
|
(Math.Abs(se.Lat) < 0.0001 && Math.Abs(se.Lon) < 0.0001))
|
|
{
|
|
errors.Add("Geofence polygon coordinates cannot be (0,0)");
|
|
}
|
|
|
|
if (nw.Lat < -90 || nw.Lat > 90 ||
|
|
se.Lat < -90 || se.Lat > 90 ||
|
|
nw.Lon < -180 || nw.Lon > 180 ||
|
|
se.Lon < -180 || se.Lon > 180)
|
|
{
|
|
errors.Add("Geofence polygon coordinates must be valid (lat: -90 to 90, lon: -180 to 180)");
|
|
}
|
|
|
|
if (nw.Lat <= se.Lat)
|
|
{
|
|
errors.Add("Geofence northWest latitude must be greater than southEast latitude");
|
|
}
|
|
}
|
|
}
|