aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/GraphClient
diff options
context:
space:
mode:
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/GraphClient')
-rw-r--r--src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs76
-rw-r--r--src/Costasdev.Busurbano.Backend/GraphClient/ResponseTypes.cs36
2 files changed, 112 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; }
+ }
+}
diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/ResponseTypes.cs b/src/Costasdev.Busurbano.Backend/GraphClient/ResponseTypes.cs
new file mode 100644
index 0000000..2d4d5df
--- /dev/null
+++ b/src/Costasdev.Busurbano.Backend/GraphClient/ResponseTypes.cs
@@ -0,0 +1,36 @@
+using System.Text.Json.Serialization;
+
+namespace Costasdev.Busurbano.Backend.GraphClient;
+
+public class GraphClientRequest
+{
+ public string OperationName { get; set; } = "Query";
+ public required string Query { get; set; }
+}
+
+public class GraphClientResponse<T> where T : AbstractGraphResponse
+{
+ [JsonPropertyName("data")]
+ public T? Data { get; set; }
+
+ [JsonPropertyName("errors")]
+ public List<GraphClientError>? Errors { get; set; }
+
+ public bool IsSuccess => Errors == null || Errors.Count == 0;
+}
+
+public interface IGraphRequest<T>
+{
+ static abstract string Query(T parameters);
+}
+
+public class AbstractGraphResponse
+{
+}
+
+public class GraphClientError
+{
+ [JsonPropertyName("message")]
+ public required string Message { get; set; }
+}
+