From bed48c3d7e49b1736d50ce42d92bb6c18cf02504 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 22 Dec 2025 22:06:06 +0100 Subject: Refactor arrivals handling and improve type definitions; reorganise components --- .../GraphClient/App/ArrivalsAtStop.cs | 20 +++++++++++++++----- .../GraphClient/App/StopTile.cs | 20 ++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src/Costasdev.Busurbano.Backend/GraphClient') diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs index 53c1165..2c34784 100644 --- a/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs +++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs @@ -5,16 +5,26 @@ namespace Costasdev.Busurbano.Backend.GraphClient.App; public class ArrivalsAtStopContent : IGraphRequest { - public record Args(string Id, int DepartureCount); + public const int PastArrivalMinutesIncluded = -15; + + public record Args(string Id, int DepartureCount, bool PastArrivals); public static string Query(Args args) { + var startTime = DateTimeOffset.Now; + if (args.PastArrivals) + { + startTime = DateTimeOffset.Now.AddMinutes(PastArrivalMinutesIncluded); + } + + var startTimeUnix = startTime.ToUnixTimeSeconds(); + return string.Create(CultureInfo.InvariantCulture, $@" query Query {{ stop(id:""{args.Id}"") {{ code name - arrivals: stoptimesWithoutPatterns(numberOfDepartures:{args.DepartureCount}) {{ + arrivals: stoptimesWithoutPatterns(numberOfDepartures:{args.DepartureCount}, startTime: {startTimeUnix}) {{ headsign scheduledDeparture pickupType @@ -40,7 +50,7 @@ public class ArrivalsAtStopContent : IGraphRequest public class ArrivalsAtStopResponse : AbstractGraphResponse { - [JsonPropertyName("stop")] public StopItem Stop { get; set; } + [JsonPropertyName("stop")] public required StopItem Stop { get; set; } public class StopItem { @@ -87,9 +97,9 @@ public class ArrivalsAtStopResponse : AbstractGraphResponse public class RouteDetails { - [JsonPropertyName("color")] public required string Color { get; set; } + [JsonPropertyName("color")] public string? Color { get; set; } - [JsonPropertyName("textColor")] public required string TextColor { get; set; } + [JsonPropertyName("textColor")] public string? TextColor { get; set; } } public class PickupType diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs index 8a271f2..802de9a 100644 --- a/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs +++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs @@ -42,35 +42,35 @@ public class StopTileResponse : AbstractGraphResponse public record Stop { [JsonPropertyName("gtfsId")] - public required string GtfsId { get; init; } + public required string GtfsId { get; set; } [JsonPropertyName("code")] - public string? Code { get; init; } + public string? Code { get; set; } [JsonPropertyName("name")] - public required string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("lat")] - public required double Lat { get; init; } + public required double Lat { get; set; } [JsonPropertyName("lon")] - public required double Lon { get; init; } + public required double Lon { get; set; } [JsonPropertyName("routes")] - public List? Routes { get; init; } + public List? Routes { get; set; } } public record Route { [JsonPropertyName("gtfsId")] - public required string GtfsId { get; init; } + public required string GtfsId { get; set; } [JsonPropertyName("shortName")] - public required string ShortName { get; init; } + public required string ShortName { get; set; } [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("textColor")] - public string? TextColor { get; init; } + public string? TextColor { get; set; } } } -- cgit v1.3