mirror of
https://github.com/sstent/FitTrack_GarminSync.git
synced 2026-01-27 01:22:03 +00:00
feat: Initial commit of FitTrack_GarminSync project
This commit is contained in:
177
examples/GarminSync/plan_phase2.md
Normal file
177
examples/GarminSync/plan_phase2.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# Implementation Improvements Needed
|
||||
|
||||
## 1. **Route Handler Completion** - HIGH PRIORITY
|
||||
|
||||
### Missing Import in `internal/web/routes.go`:
|
||||
```go
|
||||
import (
|
||||
"strconv" // ADD THIS - needed for strconv.Atoi
|
||||
// ... other imports
|
||||
)
|
||||
```
|
||||
|
||||
### Missing Route Connections in `main.go`:
|
||||
```go
|
||||
// Current setupRoutes function is incomplete - needs:
|
||||
func (app *App) setupRoutes(webHandler *web.WebHandler) *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Health check
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("OK"))
|
||||
})
|
||||
|
||||
// Web UI routes
|
||||
mux.HandleFunc("/", webHandler.Index)
|
||||
mux.HandleFunc("/activities", webHandler.ActivityList)
|
||||
mux.HandleFunc("/activity", webHandler.ActivityDetail)
|
||||
|
||||
// ADD THESE API ROUTES:
|
||||
mux.HandleFunc("/api/activities", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Implement API endpoint
|
||||
})
|
||||
mux.HandleFunc("/api/stats", func(w http.ResponseWriter, r *http.Request) {
|
||||
stats, _ := app.db.GetStats()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(stats)
|
||||
})
|
||||
mux.HandleFunc("/api/sync", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
go app.syncService.Sync(context.Background())
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "started"})
|
||||
}
|
||||
})
|
||||
|
||||
return mux
|
||||
}
|
||||
```
|
||||
|
||||
## 2. **Database Interface Issues** - HIGH PRIORITY
|
||||
|
||||
### Fix SQLiteDB Creation in `main.go`:
|
||||
```go
|
||||
// CURRENT (INCORRECT):
|
||||
app.db = database.NewSQLiteDBFromDB(dbConn)
|
||||
|
||||
// SHOULD BE:
|
||||
sqliteDB, err := database.NewSQLiteDB(dbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
app.db = sqliteDB
|
||||
```
|
||||
|
||||
### Fix Return Type Mismatch:
|
||||
Your `NewSQLiteDB` returns `*SQLiteDB` but main.go expects `Database` interface.
|
||||
|
||||
## 3. **Template Function Issues** - MEDIUM PRIORITY
|
||||
|
||||
### Missing Template Functions in `activity_detail.html`:
|
||||
```go
|
||||
// Add these template functions to web handler:
|
||||
func (h *WebHandler) LoadTemplates(templateDir string) error {
|
||||
// ... existing code ...
|
||||
|
||||
// Add custom functions
|
||||
funcMap := template.FuncMap{
|
||||
"div": func(a, b float64) float64 { return a / b },
|
||||
"formatDuration": func(seconds int) string {
|
||||
hrs := seconds / 3600
|
||||
mins := (seconds % 3600) / 60
|
||||
return fmt.Sprintf("%dh %dm", hrs, mins)
|
||||
},
|
||||
"formatMeters": func(meters float64) string {
|
||||
return fmt.Sprintf("%.0f", meters)
|
||||
},
|
||||
}
|
||||
|
||||
for _, page := range pages {
|
||||
name := filepath.Base(page)
|
||||
files := append([]string{page}, layouts...)
|
||||
files = append(files, partials...)
|
||||
|
||||
h.templates[name], err = template.New(name).Funcs(funcMap).ParseFiles(files...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
## 4. **Parser Implementation** - MEDIUM PRIORITY
|
||||
|
||||
### Complete TCX/GPX Parsers:
|
||||
The factory references them but they return `nil`. Either:
|
||||
- Implement them fully, or
|
||||
- Remove references and return proper errors
|
||||
|
||||
```go
|
||||
// In factory.go, replace:
|
||||
func NewTCXParser() Parser { return nil }
|
||||
func NewGPXParser() Parser { return nil }
|
||||
|
||||
// With:
|
||||
func NewTCXParser() Parser {
|
||||
return &TCXParser{} // Implement basic TCX parser
|
||||
}
|
||||
func NewGPXParser() Parser {
|
||||
return &GPXParser{} // Or remove if not needed
|
||||
}
|
||||
```
|
||||
|
||||
## 5. **Sync Service Integration** - MEDIUM PRIORITY
|
||||
|
||||
### Missing Sync Service in Main App:
|
||||
```go
|
||||
// In main.go App struct, add:
|
||||
type App struct {
|
||||
db *database.SQLiteDB
|
||||
cron *cron.Cron
|
||||
server *http.Server
|
||||
garmin *garmin.Client
|
||||
syncService *sync.SyncService // ADD THIS
|
||||
shutdown chan os.Signal
|
||||
}
|
||||
|
||||
// In init() method:
|
||||
app.syncService = sync.NewSyncService(app.garmin, app.db, dataDir)
|
||||
```
|
||||
|
||||
## 6. **Build Issues** - LOW PRIORITY
|
||||
|
||||
### Fix Go Module Issues:
|
||||
Your `go.mod` has some unused dependencies and wrong module path:
|
||||
|
||||
```go
|
||||
// Update go.mod:
|
||||
module garminsync // Remove github.com path if local
|
||||
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
golang.org/x/net v0.12.0
|
||||
)
|
||||
|
||||
// Remove unused dependencies like:
|
||||
// - github.com/tormoder/fit (if not actually used)
|
||||
// - Various lint tools (should be in tools.go)
|
||||
```
|
||||
|
||||
## 7. **Docker Configuration** - LOW PRIORITY
|
||||
|
||||
### Health Check Enhancement:
|
||||
```dockerfile
|
||||
# In Dockerfile, improve health check:
|
||||
HEALTHCHECK --interval=30s --timeout=30s --retries=3 \
|
||||
CMD wget --quiet --tries=1 --spider http://localhost:8888/health || exit 1
|
||||
|
||||
# Make sure wget is available or use curl:
|
||||
RUN apk add --no-cache ca-certificates tzdata wget
|
||||
```
|
||||
Reference in New Issue
Block a user