mirror of
https://github.com/sstent/go-garminconnect.git
synced 2026-02-07 15:01:38 +00:00
sync
This commit is contained in:
35
internal/api/bodycomposition.go
Normal file
35
internal/api/bodycomposition.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GetBodyComposition retrieves body composition data within a date range
|
||||
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"),
|
||||
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"),
|
||||
),
|
||||
})
|
||||
|
||||
// Execute GET request
|
||||
var results []BodyComposition
|
||||
err := c.Get(ctx, u.String(), &results)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
Reference in New Issue
Block a user