mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-27 08:31:13 +00:00
[AZ-1126] Migrate capturedAt to DateTimeOffset
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using SatelliteProvider.Common.Json;
|
||||
|
||||
namespace SatelliteProvider.Common.DTO;
|
||||
|
||||
// AZ-488 / `uav-tile-upload.md` v1.0.0 — per-tile metadata supplied with each
|
||||
// batch item. `CapturedAt` is normalized to UTC by the upload handler before
|
||||
// reaching the persistence layer.
|
||||
// AZ-488 / `uav-tile-upload.md` — per-tile metadata supplied with each batch
|
||||
// item. `CapturedAt` is UTC-aware (`DateTimeOffset`) and normalized to UTC
|
||||
// before persistence (AZ-1126 / F-AZ810-2).
|
||||
//
|
||||
// AZ-503: `FlightId` is optional. When provided, two UAVs uploading the same
|
||||
// (z, x, y) cell from different flights coexist as distinct DB rows and write
|
||||
@@ -27,7 +28,8 @@ public record UavTileMetadata
|
||||
[JsonRequired]
|
||||
public double TileSizeMeters { get; init; }
|
||||
[JsonRequired]
|
||||
public DateTime CapturedAt { get; init; }
|
||||
[JsonConverter(typeof(UtcOffsetRequiredDateTimeOffsetConverter))]
|
||||
public DateTimeOffset CapturedAt { get; init; }
|
||||
public Guid? FlightId { get; init; }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SatelliteProvider.Common.Json;
|
||||
|
||||
public sealed partial class UtcOffsetRequiredDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
||||
{
|
||||
[GeneratedRegex(@"T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2}|[+-]\d{4})$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
|
||||
private static partial Regex ExplicitOffsetPattern();
|
||||
|
||||
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.String)
|
||||
{
|
||||
throw new JsonException("`capturedAt` must be an ISO-8601 string with an explicit UTC offset.");
|
||||
}
|
||||
|
||||
var raw = reader.GetString();
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
{
|
||||
throw new JsonException("`capturedAt` must be an ISO-8601 string with an explicit UTC offset.");
|
||||
}
|
||||
|
||||
if (!ExplicitOffsetPattern().IsMatch(raw))
|
||||
{
|
||||
throw new JsonException("`capturedAt` must include an explicit UTC offset (for example `Z` or `+00:00`).");
|
||||
}
|
||||
|
||||
if (!DateTimeOffset.TryParse(raw, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var parsed))
|
||||
{
|
||||
throw new JsonException("`capturedAt` could not be parsed as an ISO-8601 timestamp.");
|
||||
}
|
||||
|
||||
return parsed.ToUniversalTime();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToUniversalTime().ToString("O", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user