aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-28 22:24:26 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-28 22:25:01 +0100
commit48ec0aae80a200d7eb50639ff4c4ca8ae564f29b (patch)
tree8cf2a2a02a49d8295985d90679c33c5bc8375818 /src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs
parentb2ddc0ef449ccbe7f0d33e539ccdfc1baef04e2c (diff)
Implement displaying routes with dynamic data from OTP
Diffstat (limited to 'src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs')
-rw-r--r--src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs
new file mode 100644
index 0000000..fc69452
--- /dev/null
+++ b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs
@@ -0,0 +1,66 @@
+using System.Globalization;
+using System.Text.Json.Serialization;
+
+namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries;
+
+public class RoutesListContent : IGraphRequest<RoutesListContent.Args>
+{
+ public record Args(string[] Feeds, string ServiceDate);
+
+ public static string Query(Args args)
+ {
+ var feedsStr = string.Join(", ", args.Feeds.Select(f => $"\"{f}\""));
+ return string.Create(CultureInfo.InvariantCulture, $$"""
+ query Query {
+ routes(feeds: [{{feedsStr}}]) {
+ gtfsId
+ shortName
+ longName
+ color
+ textColor
+ sortOrder
+ agency {
+ name
+ }
+ patterns {
+ tripsForDate(serviceDate: "{{args.ServiceDate}}") {
+ id
+ }
+ }
+ }
+ }
+ """);
+ }
+}
+
+public class RoutesListResponse : AbstractGraphResponse
+{
+ [JsonPropertyName("routes")] public List<RouteItem> Routes { get; set; } = [];
+
+ public class RouteItem
+ {
+ [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; }
+ [JsonPropertyName("shortName")] public string? ShortName { get; set; }
+ [JsonPropertyName("longName")] public string? LongName { get; set; }
+ [JsonPropertyName("color")] public string? Color { get; set; }
+ [JsonPropertyName("textColor")] public string? TextColor { get; set; }
+ [JsonPropertyName("sortOrder")] public int? SortOrder { get; set; }
+ [JsonPropertyName("agency")] public AgencyItem? Agency { get; set; }
+ [JsonPropertyName("patterns")] public List<PatternItem> Patterns { get; set; } = [];
+ }
+
+ public class AgencyItem
+ {
+ [JsonPropertyName("name")] public string? Name { get; set; }
+ }
+
+ public class PatternItem
+ {
+ [JsonPropertyName("tripsForDate")] public List<TripItem> TripsForDate { get; set; } = [];
+ }
+
+ public class TripItem
+ {
+ [JsonPropertyName("id")] public string? Id { get; set; }
+ }
+}