From d4e4616ba49f3a18a52e3197e1c77639a93b0330 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 11 Aug 2026 12:38:45 +0200 Subject: feat: Add ride detail map --- web/views.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'web/views.go') diff --git a/web/views.go b/web/views.go index a9ffffa..f6e84d5 100644 --- a/web/views.go +++ b/web/views.go @@ -5,6 +5,7 @@ import ( "net/url" "time" + "github.com/martinlehoux/biking_home/ride" "github.com/martinlehoux/biking_home/rides" ) @@ -14,6 +15,29 @@ type RideView struct { CotacolPer100Km string } +type RideDetailView struct { + RideView + Route GeoJSONFeatureCollection + HasRoute bool + RouteError string +} + +type GeoJSONFeatureCollection struct { + Type string `json:"type"` + Features []GeoJSONFeature `json:"features"` +} + +type GeoJSONFeature struct { + Type string `json:"type"` + Geometry GeoJSONGeometry `json:"geometry"` + Properties map[string]any `json:"properties,omitempty"` +} + +type GeoJSONGeometry struct { + Type string `json:"type"` + Coordinates [][]float64 `json:"coordinates"` +} + type RideSort struct { Column string Descending bool @@ -122,6 +146,32 @@ func rideSortHeaders(current RideSort) []RideSortHeader { return headers } +func rideDetailURL(id int64) string { + return fmt.Sprintf("/rides/%d", id) +} + +func buildRideDetailView(item rides.Ride, parsed ride.Ride) RideDetailView { + coordinates := make([][]float64, parsed.Len()) + for i := 0; i < parsed.Len(); i++ { + coordinate := parsed.Coord(i) + coordinates[i] = []float64{coordinate.Lon, coordinate.Lat} + } + return RideDetailView{ + RideView: buildRideView(item), + Route: GeoJSONFeatureCollection{ + Type: "FeatureCollection", + Features: []GeoJSONFeature{{ + Type: "Feature", + Geometry: GeoJSONGeometry{ + Type: "LineString", + Coordinates: coordinates, + }, + }}, + }, + HasRoute: true, + } +} + type SyncPageData struct { From string To string -- cgit v1.2.3