porting - part2 wk1 done

This commit is contained in:
2025-09-07 18:34:53 -07:00
parent dccb072f73
commit 5c44f01bc3
5 changed files with 919 additions and 4 deletions

View File

@@ -1,10 +1,14 @@
package data
import (
"encoding/json"
"fmt"
"sort"
"time"
"garmin-connect/garth/client"
"garmin-connect/garth/errors"
"garmin-connect/garth/utils"
)
// DailyBodyBatteryStress represents complete daily Body Battery and stress data
@@ -109,8 +113,37 @@ func ParseStressReadings(valuesArray [][]int) []StressReading {
// Get implements the Data interface for DailyBodyBatteryStress
func (d *DailyBodyBatteryStress) Get(day time.Time, client *client.Client) (any, error) {
// Implementation to be added
return nil, nil
dateStr := day.Format("2006-01-02")
path := fmt.Sprintf("/wellness-service/wellness/dailyStress/%s", dateStr)
response, err := client.ConnectAPI(path, "GET", nil)
if err != nil {
return nil, err
}
if response == nil {
return nil, nil
}
responseMap, ok := response.(map[string]interface{})
if !ok {
return nil, &errors.IOError{GarthError: errors.GarthError{
Message: "Invalid response format"}}
}
snakeResponse := utils.CamelToSnakeDict(responseMap)
jsonBytes, err := json.Marshal(snakeResponse)
if err != nil {
return nil, err
}
var result DailyBodyBatteryStress
if err := json.Unmarshal(jsonBytes, &result); err != nil {
return nil, err
}
return &result, nil
}
// List implements the Data interface for concurrent fetching

View File

@@ -1,9 +1,13 @@
package data
import (
"encoding/json"
"fmt"
"time"
"garmin-connect/garth/client"
"garmin-connect/garth/errors"
"garmin-connect/garth/utils"
)
// SleepScores represents sleep scoring data
@@ -37,8 +41,47 @@ type DailySleepDTO struct {
// Get implements the Data interface for DailySleepDTO
func (d *DailySleepDTO) Get(day time.Time, client *client.Client) (any, error) {
// Implementation to be added
return nil, nil
dateStr := day.Format("2006-01-02")
path := fmt.Sprintf("/wellness-service/wellness/dailySleepData/%s?nonSleepBufferMinutes=60&date=%s",
client.Username, dateStr)
response, err := client.ConnectAPI(path, "GET", nil)
if err != nil {
return nil, err
}
if response == nil {
return nil, nil
}
responseMap, ok := response.(map[string]interface{})
if !ok {
return nil, &errors.IOError{GarthError: errors.GarthError{
Message: "Invalid response format"}}
}
snakeResponse := utils.CamelToSnakeDict(responseMap)
dailySleepDto, exists := snakeResponse["daily_sleep_dto"].(map[string]interface{})
if !exists || dailySleepDto["id"] == nil {
return nil, nil // No sleep data
}
jsonBytes, err := json.Marshal(snakeResponse)
if err != nil {
return nil, err
}
var result struct {
DailySleepDTO *DailySleepDTO `json:"daily_sleep_dto"`
SleepMovement []SleepMovement `json:"sleep_movement"`
}
if err := json.Unmarshal(jsonBytes, &result); err != nil {
return nil, err
}
return result, nil
}
// List implements the Data interface for concurrent fetching