From 1edd1c39f2a0e83421df77401625f6151ce4864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bahattin=20=C3=87ini=C3=A7?= Date: Sat, 8 Jun 2024 12:14:36 +0300 Subject: [PATCH] fix(data): Correct gear type identification for running shoes in Strava API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a workaround for a bug in the Strava API that incorrectly returns all gear as bicycles. - Identified running shoes by checking if the gear ID starts with "g" and set the frame type to "Shoes". - Updated the `updateGears` function to apply this workaround and correctly set the gear type. Signed-off-by: Bahattin Çiniç --- importer/importer.go | 11 ++++++++++- models/gear.go | 4 ++-- ui/src/pages/AthletesPage.vue | 8 ++++---- ui/src/pages/GearsPage.vue | 9 +++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/importer/importer.go b/importer/importer.go index 1750ab7..49ad618 100644 --- a/importer/importer.go +++ b/importer/importer.go @@ -3,6 +3,7 @@ package importer import ( "context" "encoding/json" + "strings" "github.com/bahattincinic/fitwave/config" "github.com/bahattincinic/fitwave/database" @@ -36,6 +37,14 @@ func (im *Importer) updateGears(tx *gorm.DB, gears []client.GearDetailed, user * var rows []models.Gear for _, gear := range gears { + frameType := gear.FrameType.String() + + // There is a bug in the Strava API that incorrectly returns all gear as bicycles. + // We can identify running shoes by checking if the gear ID starts with "g". + if strings.HasPrefix(gear.Id, "g") { + frameType = "Shoes" + } + rows = append(rows, models.Gear{ Id: gear.Id, Name: gear.Name, @@ -43,7 +52,7 @@ func (im *Importer) updateGears(tx *gorm.DB, gears []client.GearDetailed, user * Distance: gear.Distance, BrandName: gear.BrandName, ModelName: gear.ModelName, - FrameType: gear.FrameType.String(), + Type: frameType, Description: gear.Description, AthleteID: user.Athlete.Id, }) diff --git a/models/gear.go b/models/gear.go index 94fb7d9..388f50a 100644 --- a/models/gear.go +++ b/models/gear.go @@ -7,8 +7,8 @@ type Gear struct { Distance float64 `json:"distance"` BrandName string `json:"brand_name"` ModelName string `json:"model_name"` - FrameType string `json:"frame_type"` + Type string `json:"type"` Description string `json:"description"` AthleteID int64 - Athlete Athlete `gorm:"foreignkey:AthleteID" json:"athlete"` + Athlete *Athlete `gorm:"foreignkey:AthleteID" json:"athlete"` } diff --git a/ui/src/pages/AthletesPage.vue b/ui/src/pages/AthletesPage.vue index 387dfa3..9eddf07 100644 --- a/ui/src/pages/AthletesPage.vue +++ b/ui/src/pages/AthletesPage.vue @@ -16,10 +16,10 @@ @rowSelect="onRowSelect" > - - - - + + + + diff --git a/ui/src/pages/GearsPage.vue b/ui/src/pages/GearsPage.vue index 88823cb..64645ce 100644 --- a/ui/src/pages/GearsPage.vue +++ b/ui/src/pages/GearsPage.vue @@ -15,10 +15,11 @@ selectionMode="single" @rowSelect="onRowSelect" > - - - - + + + + +