aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Sources.OpenTripPlannerGql/Queries/StopTile.cs
blob: 6079ea37e3da75948fe9346628a2b49e604b0bf7 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Globalization;
using System.Text.Json.Serialization;

namespace Enmarcha.Sources.OpenTripPlannerGql.Queries;

public class StopTileRequestContent : IGraphRequest<StopTileRequestContent.TileRequestParams>
{
    public record TileRequestParams(
        double MinLon,
        double MinLat,
        double MaxLon,
        double MaxLat,
        string[]? Feeds = null
    );

    public static string Query(TileRequestParams req)
    {
        var feedsFilter = req.Feeds != null && req.Feeds.Length > 0
            ? $"feeds: [{string.Join(", ", req.Feeds.Select(f => $"\"{f}\""))}]"
            : string.Empty;

        return string.Create(CultureInfo.InvariantCulture, $@"
        query Query {{
            stopsByBbox(
                minLat: {req.MinLat:F6}
                minLon: {req.MinLon:F6}
                maxLon: {req.MaxLon:F6}
                maxLat: {req.MaxLat:F6}
                {feedsFilter}
            ) {{
                gtfsId
                code
                name
                lat
                lon
                routes {{
                    gtfsId
                    shortName
                    color
                    textColor
                }}
            }}
        }}
        ");
    }
}

public class StopTileResponse : AbstractGraphResponse
{
    [JsonPropertyName("stopsByBbox")]
    public List<Stop>? StopsByBbox { get; set; }

    public record Stop
    {
        [JsonPropertyName("gtfsId")]
        public required string GtfsId { get; set; }

        [JsonPropertyName("code")]
        public string? Code { get; set; }

        [JsonPropertyName("name")]
        public required string Name { get; set; }

        [JsonPropertyName("lat")]
        public required double Lat { get; set; }

        [JsonPropertyName("lon")]
        public required double Lon { get; set; }

        [JsonPropertyName("routes")]
        public List<Route>? Routes { get; set; }
    }

    public record Route
    {
        [JsonPropertyName("gtfsId")]
        public required string GtfsId { get; set; }
        [JsonPropertyName("shortName")]
        public required string ShortName { get; set; }

        [JsonPropertyName("color")]
        public string? Color { get; set; }

        [JsonPropertyName("textColor")]
        public string? TextColor { get; set; }
    }
}