aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-02-11 16:10:03 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-02-11 16:17:19 +0100
commita187bcf97de6d043cb663dd973c83cc887665d3a (patch)
treef4d13c329b7e5332dfa824e5c832209cf053afb4 /src
parent800a3004af4320881825399b5a197b4557ec516e (diff)
feat: Update OpenTelemetry package versions and enhance route color
handling in OtpService Closes #132
Diffstat (limited to 'src')
-rw-r--r--src/Enmarcha.Backend/Services/OtpService.cs33
1 files changed, 29 insertions, 4 deletions
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()
};