summaryrefslogtreecommitdiff
path: root/web/views.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/views.go')
-rw-r--r--web/views.go50
1 files changed, 50 insertions, 0 deletions
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