diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2026-02-11 16:10:03 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2026-02-11 16:17:19 +0100 |
| commit | a187bcf97de6d043cb663dd973c83cc887665d3a (patch) | |
| tree | f4d13c329b7e5332dfa824e5c832209cf053afb4 | |
| parent | 800a3004af4320881825399b5a197b4557ec516e (diff) | |
feat: Update OpenTelemetry package versions and enhance route color
handling in OtpService
Closes #132
| -rw-r--r-- | Directory.Packages.props | 8 | ||||
| -rw-r--r-- | src/Enmarcha.Backend/Services/OtpService.cs | 33 |
2 files changed, 33 insertions, 8 deletions
diff --git a/Directory.Packages.props b/Directory.Packages.props index 9bf5796..3ded0a5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,9 +21,9 @@ <PackageVersion Include="CsvHelper" Version="33.1.0" /> <PackageVersion Include="FuzzySharp" Version="2.0.2" /> - <PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.11.1" /> - <PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.0" /> - <PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.11.0" /> - <PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.1" /> + <PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.15" /> + <PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.0" /> + <PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0" /> + <PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.0" /> </ItemGroup> </Project> diff --git a/src/Enmarcha.Backend/Services/OtpService.cs b/src/Enmarcha.Backend/Services/OtpService.cs index 1484583..07c4d81 100644 --- a/src/Enmarcha.Backend/Services/OtpService.cs +++ b/src/Enmarcha.Backend/Services/OtpService.cs @@ -35,13 +35,25 @@ public class OtpService public RouteDto MapRoute(RoutesListResponse.RouteItem route) { var feedId = route.GtfsId.Split(':')[0]; + var color = route.Color; + if (!string.IsNullOrWhiteSpace(color)) + { + if (!color.StartsWith("#")) color = "#" + color; + } + + if (string.IsNullOrWhiteSpace(color) || color.Length != 7) + { + (color, _) = _feedService.GetFallbackColourForFeed(feedId); + } + + var textColor = ContrastHelper.GetBestTextColour(color.TrimStart('#')); return new RouteDto { Id = route.GtfsId, ShortName = _feedService.NormalizeRouteShortName(feedId, route.ShortName ?? string.Empty), LongName = route.LongName, - Color = route.Color, - TextColor = route.TextColor, + Color = color, + TextColor = textColor, SortOrder = route.SortOrder, AgencyName = route.Agency?.Name, TripCount = route.Patterns.Sum(p => p.TripsForDate.Count) @@ -51,12 +63,25 @@ public class OtpService public RouteDetailsDto MapRouteDetails(RouteDetailsResponse.RouteItem route) { var feedId = route.GtfsId?.Split(':')[0] ?? "unknown"; + var color = route.Color; + if (!string.IsNullOrWhiteSpace(color)) + { + if (!color.StartsWith("#")) color = "#" + color; + } + + if (string.IsNullOrWhiteSpace(color) || color.Length != 7) + { + (color, _) = _feedService.GetFallbackColourForFeed(feedId); + } + + var textColor = ContrastHelper.GetBestTextColour(color.TrimStart('#')); + return new RouteDetailsDto { ShortName = _feedService.NormalizeRouteShortName(feedId, route.ShortName ?? string.Empty), LongName = route.LongName, - Color = route.Color, - TextColor = route.TextColor, + Color = color, + TextColor = textColor, AgencyName = route.Agency?.Name, Patterns = route.Patterns.Select(p => MapPattern(p, feedId)).ToList() }; |
