[AZ-370] Refactor C17: status / point-type enums + AC RT2 update

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>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-11 03:55:22 +03:00
parent 6d98c8f8d1
commit 23ab05766d
29 changed files with 357 additions and 84 deletions
@@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SatelliteProvider.Common.Configs;
using SatelliteProvider.Common.DTO;
using SatelliteProvider.Common.Enums;
using SatelliteProvider.Common.Exceptions;
using SatelliteProvider.Common.Imaging;
using SatelliteProvider.Common.Interfaces;
@@ -38,7 +39,7 @@ public class RegionService : IRegionService
_logger = logger;
}
public async Task<RegionStatus> RequestRegionAsync(Guid id, double latitude, double longitude, double sizeMeters, int zoomLevel, bool stitchTiles = false)
public async Task<RegionStatusResponse> RequestRegionAsync(Guid id, double latitude, double longitude, double sizeMeters, int zoomLevel, bool stitchTiles = false)
{
// AZ-362: idempotent POST contract. A retried POST with the same caller-supplied
// Id returns the existing region instead of bubbling a unique-key violation.
@@ -47,7 +48,7 @@ public class RegionService : IRegionService
{
_logger.LogInformation(
"Idempotent region POST: id {RegionId} already exists with status {Status}; returning existing resource without re-enqueueing",
id, existing.Status);
id, existing.Status.ToString().ToLowerInvariant());
return MapToStatus(existing);
}
@@ -60,7 +61,7 @@ public class RegionService : IRegionService
SizeMeters = sizeMeters,
ZoomLevel = zoomLevel,
StitchTiles = stitchTiles,
Status = "queued",
Status = RegionStatus.Queued,
TilesDownloaded = 0,
TilesReused = 0,
CreatedAt = now,
@@ -84,7 +85,7 @@ public class RegionService : IRegionService
return MapToStatus(region);
}
public async Task<RegionStatus?> GetRegionStatusAsync(Guid id)
public async Task<RegionStatusResponse?> GetRegionStatusAsync(Guid id)
{
var region = await _regionRepository.GetByIdAsync(id);
return region != null ? MapToStatus(region) : null;
@@ -101,7 +102,7 @@ public class RegionService : IRegionService
return;
}
region.Status = "processing";
region.Status = RegionStatus.Processing;
region.UpdatedAt = DateTime.UtcNow;
await _regionRepository.UpdateAsync(region);
@@ -151,7 +152,7 @@ public class RegionService : IRegionService
await GenerateSummaryFileAsync(summaryPath, id, region, tiles, tilesDownloaded, tilesReused, stitchedImagePath, processingStartTime, linkedCts.Token, errorMessage);
region.Status = "completed";
region.Status = RegionStatus.Completed;
region.CsvFilePath = csvPath;
region.SummaryFilePath = summaryPath;
region.TilesDownloaded = tilesDownloaded;
@@ -182,7 +183,7 @@ public class RegionService : IRegionService
int tilesReused,
string errorMessage)
{
region.Status = "failed";
region.Status = RegionStatus.Failed;
region.UpdatedAt = DateTime.UtcNow;
try
@@ -311,7 +312,7 @@ public class RegionService : IRegionService
summary.AppendLine($"Center: {region.Latitude:F6}, {region.Longitude:F6}");
summary.AppendLine($"Size: {region.SizeMeters:F0} meters");
summary.AppendLine($"Zoom Level: {region.ZoomLevel}");
summary.AppendLine($"Status: {region.Status}");
summary.AppendLine($"Status: {region.Status.ToString().ToLowerInvariant()}");
summary.AppendLine();
if (!string.IsNullOrEmpty(errorMessage))
@@ -328,7 +329,7 @@ public class RegionService : IRegionService
summary.AppendLine($"- Processing Time: {processingTime:F2} seconds");
summary.AppendLine($"- Started: {startTime:yyyy-MM-dd HH:mm:ss} UTC");
if (region.Status == "completed")
if (region.Status == RegionStatus.Completed)
{
summary.AppendLine($"- Completed: {endTime:yyyy-MM-dd HH:mm:ss} UTC");
}
@@ -356,9 +357,9 @@ public class RegionService : IRegionService
await File.WriteAllTextAsync(filePath, summary.ToString(), cancellationToken);
}
private static RegionStatus MapToStatus(RegionEntity region)
private static RegionStatusResponse MapToStatus(RegionEntity region)
{
return new RegionStatus
return new RegionStatusResponse
{
Id = region.Id,
Status = region.Status,