From 91f7d7dd5a4ca8453cfdbc9a3beeb216b6638ef7 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 22 Dec 2025 14:13:45 +0100 Subject: Implement fetching scheduled arrivals for stop --- .../GraphClient/App/ArrivalsAtStop.cs | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs (limited to 'src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs') diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs new file mode 100644 index 0000000..dfecdd6 --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs @@ -0,0 +1,82 @@ +using System.Globalization; +using System.Text.Json.Serialization; + +namespace Costasdev.Busurbano.Backend.GraphClient.App; + +public class ArrivalsAtStopContent : IGraphRequest +{ + public static string Query(string id) + { + return string.Create(CultureInfo.InvariantCulture, $@" + query Query {{ + stop(id:""{id}"") {{ + code + name + arrivals: stoptimesWithoutPatterns(numberOfDepartures:10) {{ + trip {{ + gtfsId + routeShortName + route {{ + color + textColor + }} + }} + headsign + scheduledDeparture + }} + }} + }} + "); + } +} + +public class ArrivalsAtStopResponse : AbstractGraphResponse +{ + [JsonPropertyName("stop")] + public StopItem Stop { get; set; } + + public class StopItem + { + [JsonPropertyName("code")] + public required string Code { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonPropertyName("arrivals")] + public List Arrivals { get; set; } = []; + } + + public class Arrival + { + [JsonPropertyName("headsign")] + public required string Headsign { get; set; } + + [JsonPropertyName("scheduledDeparture")] + public int ScheduledDepartureSeconds { get; set; } + + [JsonPropertyName("trip")] + public required TripDetails Trip { get; set; } + } + + public class TripDetails + { + [JsonPropertyName("gtfsId")] + public required string GtfsId { get; set; } + + [JsonPropertyName("routeShortName")] + public required string RouteShortName { get; set; } + + [JsonPropertyName("route")] + public required RouteDetails Route { get; set; } + } + + public class RouteDetails + { + [JsonPropertyName("color")] + public required string Color { get; set; } + + [JsonPropertyName("textColor")] + public required string TextColor { get; set; } + } +} -- cgit v1.3