feat: Implement Phase 1C.1: Core Download Infrastructure

This commit is contained in:
2025-09-18 14:19:53 -07:00
parent 2870d23fed
commit f7acfd7c78
3 changed files with 36 additions and 11 deletions

View File

@@ -56,6 +56,7 @@ var (
// Flags for downloadActivitiesCmd
downloadFormat string
outputDir string
)
func init() {
@@ -72,6 +73,7 @@ func init() {
activitiesCmd.AddCommand(downloadActivitiesCmd)
downloadActivitiesCmd.Flags().StringVar(&downloadFormat, "format", "gpx", "Download format (gpx, tcx, csv)")
downloadActivitiesCmd.Flags().StringVar(&outputDir, "output-dir", ".", "Output directory for downloaded files")
activitiesCmd.AddCommand(searchActivitiesCmd)
searchActivitiesCmd.Flags().StringP("query", "q", "", "Query string to search for activities")
@@ -179,11 +181,11 @@ func runDownloadActivity(cmd *cobra.Command, args []string) error {
}
opts := garmin.DownloadOptions{
Format: downloadFormat,
// TODO: Add other download options from flags
Format: downloadFormat,
OutputDir: outputDir,
}
fmt.Printf("Downloading activity %d in %s format...\n", activityID, downloadFormat)
fmt.Printf("Downloading activity %d in %s format to %s...\n", activityID, downloadFormat, outputDir)
if err := garminClient.DownloadActivity(activityID, opts); err != nil {
return fmt.Errorf("failed to download activity: %w", err)
}

View File

@@ -290,17 +290,17 @@ func (c *Client) DownloadActivity(id string, opts *DownloadOptions) error {
```
**Tasks:**
- [ ] Research Garmin's download endpoints
- [ ] Implement format detection and conversion
- [ ] Add file writing with proper naming
- [x] Research Garmin's download endpoints
- [x] Implement format detection and conversion
- [x] Add file writing with proper naming
- [ ] Implement progress indication
- [ ] Add download validation
- [ ] Error handling for failed downloads
- [x] Error handling for failed downloads
**Deliverables:**
- [ ] Working download for at least GPX format
- [x] Working download for at least GPX format
- [ ] Progress indication during download
- [ ] Proper error handling
- [x] Proper error handling
#### 1C.2: Multi-Format Support
**Duration: 2 days**

View File

@@ -76,8 +76,31 @@ func (c *Client) GetActivity(activityID int) (*activities.ActivityDetail, error)
// DownloadActivity downloads activity data
func (c *Client) DownloadActivity(activityID int, opts activities.DownloadOptions) error {
// TODO: Implement internalClient.Client.DownloadActivity
return fmt.Errorf("not implemented")
// TODO: Determine file extension based on format
fileExtension := opts.Format
if fileExtension == "csv" {
fileExtension = "csv"
} else if fileExtension == "gpx" {
fileExtension = "gpx"
} else if fileExtension == "tcx" {
fileExtension = "tcx"
} else {
return fmt.Errorf("unsupported download format: %s", opts.Format)
}
// Construct filename
filename := fmt.Sprintf("%d.%s", activityID, fileExtension)
if opts.Filename != "" {
filename = opts.Filename
}
// Construct output path
outputPath := filename
if opts.OutputDir != "" {
outputPath = filepath.Join(opts.OutputDir, filename)
}
return c.Client.Download(fmt.Sprintf("%d", activityID), outputPath)
}
// SearchActivities searches for activities by a query string