Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nordbergmikael committed Aug 12, 2024
1 parent afa7185 commit 9e208b1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/pkg/application/measurements/measurementsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewMeasurementsClient(ctx context.Context, url, oauthTokenURL, oauthClientI
}

func (c measurementsClient) GetMaxValue(ctx context.Context, measurmentID string) (float64, error) {
aggrResult, err := c.GetAggrValue(ctx, measurmentID, "max")
aggrResult, err := c.getAggrValue(ctx, measurmentID, "max")
if err != nil {
return 0.0, err
}
Expand All @@ -87,8 +87,12 @@ func (c measurementsClient) GetMaxValue(ctx context.Context, measurmentID string
return *aggrResult.Maximum, nil
}

func (c measurementsClient) GetAggrValue(ctx context.Context, measurmentID string, aggrMethods ...string) (*AggrResult, error) {
jar, err := c.getAggrValues(ctx, measurmentID, aggrMethods...)
func (c measurementsClient) getAggrValue(ctx context.Context, measurmentID string, aggrMethods ...string) (*AggrResult, error) {
params := url.Values{}
params.Add("id", measurmentID)
params.Add("aggrMethods", strings.Join(aggrMethods, ","))

jar, err := c.getApiResponse(ctx, params)
if err != nil {
return nil, err
}
Expand All @@ -102,17 +106,13 @@ func (c measurementsClient) GetAggrValue(ctx context.Context, measurmentID strin
return &aggrResult, nil
}

func (c measurementsClient) getAggrValues(ctx context.Context, measurmentID string, aggrMethods ...string) (*jsonApiResponse, error) {
func (c measurementsClient) getApiResponse(ctx context.Context, params url.Values) (*jsonApiResponse, error) {
var err error
ctx, span := tracer.Start(ctx, "get-aggr-values")
ctx, span := tracer.Start(ctx, "get-measurement-values")
defer func() { tracing.RecordAnyErrorAndEndSpan(err, span) }()

log := logging.GetFromContext(ctx)

params := url.Values{}
params.Add("id", measurmentID)
params.Add("aggrMethods", strings.Join(aggrMethods, ","))

url := fmt.Sprintf("%s/%s?%s", c.url, "api/v0/measurements", params.Encode())

cachedItem, found := c.cache.Get(url)
Expand Down

0 comments on commit 9e208b1

Please sign in to comment.