mirror of
https://github.com/sstent/go-garminconnect.git
synced 2026-02-02 20:41:57 +00:00
with garth
This commit is contained in:
@@ -10,25 +10,22 @@ import (
|
||||
func (c *Client) GetBodyComposition(ctx context.Context, req BodyCompositionRequest) ([]BodyComposition, error) {
|
||||
// Validate date range
|
||||
if req.StartDate.IsZero() || req.EndDate.IsZero() || req.StartDate.After(req.EndDate) {
|
||||
return nil, fmt.Errorf("invalid date range: start %s to end %s",
|
||||
req.StartDate.Format("2006-01-02"),
|
||||
return nil, fmt.Errorf("invalid date range: start %s to end %s",
|
||||
req.StartDate.Format("2006-01-02"),
|
||||
req.EndDate.Format("2006-01-02"))
|
||||
}
|
||||
|
||||
// Build URL with query parameters
|
||||
u := c.baseURL.ResolveReference(&url.URL{
|
||||
Path: "/body-composition",
|
||||
RawQuery: fmt.Sprintf("startDate=%s&endDate=%s",
|
||||
req.StartDate.Format("2006-01-02"),
|
||||
req.EndDate.Format("2006-01-02"),
|
||||
),
|
||||
})
|
||||
// Build query parameters
|
||||
params := url.Values{}
|
||||
params.Add("startDate", req.StartDate.Format("2006-01-02"))
|
||||
params.Add("endDate", req.EndDate.Format("2006-01-02"))
|
||||
path := fmt.Sprintf("/body-composition?%s", params.Encode())
|
||||
|
||||
// Execute GET request
|
||||
var results []BodyComposition
|
||||
err := c.Get(ctx, u.String(), &results)
|
||||
err := c.Get(ctx, path, &results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to get body composition: %w", err)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
|
||||
Reference in New Issue
Block a user