diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-19 13:06:27 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-19 13:06:27 +0100 |
| commit | 2a9aca302485bc08f5b2dd2a54987de6f80fc338 (patch) | |
| tree | 38171abad21b2952eca6ff9e8534545b4c28ed12 /src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs | |
| parent | 37cdb0c418a7f2b47e40ae9db7ad86e1fddc86fe (diff) | |
Implement loading stops as tiles from OTP
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs')
| -rw-r--r-- | src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs new file mode 100644 index 0000000..8a271f2 --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs @@ -0,0 +1,76 @@ +using System.Globalization; +using System.Text.Json.Serialization; + +namespace Costasdev.Busurbano.Backend.GraphClient.App; + +public class StopTileRequestContent : IGraphRequest<StopTileRequestContent.Bbox> +{ + public record Bbox(double MinLon, double MinLat, double MaxLon, double MaxLat); + + public static string Query(Bbox bbox) + { + return string.Create(CultureInfo.InvariantCulture, $@" + query Query {{ + stopsByBbox( + minLat: {bbox.MinLat:F6} + minLon: {bbox.MinLon:F6} + maxLon: {bbox.MaxLon:F6} + maxLat: {bbox.MaxLat:F6} + ) {{ + 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; init; } + + [JsonPropertyName("code")] + public string? Code { get; init; } + + [JsonPropertyName("name")] + public required string Name { get; init; } + + [JsonPropertyName("lat")] + public required double Lat { get; init; } + + [JsonPropertyName("lon")] + public required double Lon { get; init; } + + [JsonPropertyName("routes")] + public List<Route>? Routes { get; init; } + } + + public record Route + { + [JsonPropertyName("gtfsId")] + public required string GtfsId { get; init; } + [JsonPropertyName("shortName")] + public required string ShortName { get; init; } + + [JsonPropertyName("color")] + public string? Color { get; init; } + + [JsonPropertyName("textColor")] + public string? TextColor { get; init; } + } +} |
