mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 16:01:14 +00:00
23ab05766d
Replaces bare strings with two enums in Common/Enums/:
RegionStatus { Queued, Processing, Completed, Failed }
RoutePointType { Start, End, Action, Intermediate }
Adds a Dapper EnumStringTypeHandler<T> (DataAccess/TypeHandlers/)
that round-trips enums to/from lowercase strings, registered once
at startup via DapperEnumTypeHandlers.RegisterAll(). DataAccess now
references Common (project ref) so entities can carry the enum types.
Sites converted: RegionService (5), RouteProcessingService (3),
RoutePointGraphBuilder (4), entity Status/PointType columns. Log
message and summary file format preserved via .ToLowerInvariant().
API JSON contract preserved by adding JsonStringEnumConverter with
JsonNamingPolicy.CamelCase to the http JSON options — single-word
enum members serialize to the same lowercase strings as before.
DTO renamed: Common.DTO.RegionStatus -> RegionStatusResponse to
free the RegionStatus name for the new enum (forced by the task's
explicit enum name); the renamed DTO has no public-API impact at
the JSON wire level. Stale doc references updated.
AC RT2 in _docs/00_problem/acceptance_criteria.md now lists all 4
point types (start/end/action/intermediate).
Tests: 171 / 171 unit + 5 / 5 smoke green (was 141 + 5; +30 new tests
covering type handler round-trip, set/parse, unknown-value rejection,
idempotent registration, and the AC RT2 doc check).
Co-authored-by: Cursor <cursoragent@cursor.com>
91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using Microsoft.Extensions.Options;
|
|
using SatelliteProvider.Common.Configs;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Common.Enums;
|
|
using SatelliteProvider.Common.Utils;
|
|
|
|
namespace SatelliteProvider.Services.RouteManagement;
|
|
|
|
public class RoutePointGraphBuilder
|
|
{
|
|
private readonly double _maxPointSpacingMeters;
|
|
|
|
public RoutePointGraphBuilder(IOptions<ProcessingConfig> processingConfig)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(processingConfig);
|
|
_maxPointSpacingMeters = processingConfig.Value.MaxRoutePointSpacingMeters;
|
|
}
|
|
|
|
public RoutePointGraph Build(IReadOnlyList<RoutePoint> userPoints)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(userPoints);
|
|
if (userPoints.Count < 2)
|
|
{
|
|
throw new ArgumentException("Route must have at least 2 points", nameof(userPoints));
|
|
}
|
|
|
|
var allPoints = new List<RoutePointDto>();
|
|
var totalDistance = 0.0;
|
|
var sequenceNumber = 0;
|
|
|
|
for (int segmentIndex = 0; segmentIndex < userPoints.Count; segmentIndex++)
|
|
{
|
|
var current = userPoints[segmentIndex];
|
|
var isStart = segmentIndex == 0;
|
|
var isEnd = segmentIndex == userPoints.Count - 1;
|
|
|
|
var currentGeo = new GeoPoint(current.Latitude, current.Longitude);
|
|
|
|
double? distanceFromPrevious = null;
|
|
if (allPoints.Count > 0)
|
|
{
|
|
var prev = allPoints[^1];
|
|
var prevGeo = new GeoPoint(prev.Latitude, prev.Longitude);
|
|
distanceFromPrevious = GeoUtils.CalculateDistance(prevGeo, currentGeo);
|
|
totalDistance += distanceFromPrevious.Value;
|
|
}
|
|
|
|
allPoints.Add(new RoutePointDto
|
|
{
|
|
Latitude = current.Latitude,
|
|
Longitude = current.Longitude,
|
|
PointType = isStart ? RoutePointType.Start : (isEnd ? RoutePointType.End : RoutePointType.Action),
|
|
SequenceNumber = sequenceNumber++,
|
|
SegmentIndex = segmentIndex,
|
|
DistanceFromPrevious = distanceFromPrevious,
|
|
});
|
|
|
|
if (isEnd)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var next = userPoints[segmentIndex + 1];
|
|
var nextGeo = new GeoPoint(next.Latitude, next.Longitude);
|
|
var intermediates = GeoUtils.CalculateIntermediatePoints(currentGeo, nextGeo, _maxPointSpacingMeters);
|
|
|
|
foreach (var intermediateGeo in intermediates)
|
|
{
|
|
var prev = allPoints[^1];
|
|
var prevGeo = new GeoPoint(prev.Latitude, prev.Longitude);
|
|
var distFromPrev = GeoUtils.CalculateDistance(prevGeo, intermediateGeo);
|
|
totalDistance += distFromPrev;
|
|
|
|
allPoints.Add(new RoutePointDto
|
|
{
|
|
Latitude = intermediateGeo.Lat,
|
|
Longitude = intermediateGeo.Lon,
|
|
PointType = RoutePointType.Intermediate,
|
|
SequenceNumber = sequenceNumber++,
|
|
SegmentIndex = segmentIndex,
|
|
DistanceFromPrevious = distFromPrev,
|
|
});
|
|
}
|
|
}
|
|
|
|
return new RoutePointGraph(allPoints, totalDistance);
|
|
}
|
|
}
|
|
|
|
public record RoutePointGraph(IReadOnlyList<RoutePointDto> Points, double TotalDistanceMeters);
|