aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs
blob: 71360ee622d6ea64d8004def9d398ca2e346912e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Globalization;
using System.Text.Json.Serialization;

namespace Enmarcha.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; }
    }
}