From b94b9c16f9f7eaaaf8e50a63feb235f5a75de0f6 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Tue, 15 Oct 2024 10:11:26 +0200 Subject: [PATCH] fix(subscription): Handle multiple status in GetList --- go.mod | 1 + go.sum | 4 ++++ lago.go | 5 ++++- subscription.go | 24 ++++++++++-------------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 895de76..f5e994c 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require github.com/google/uuid v1.4.0 require ( github.com/go-resty/resty/v2 v2.11.0 github.com/golang-jwt/jwt/v5 v5.0.0 + github.com/google/go-querystring v1.1.0 // indirect ) require golang.org/x/net v0.23.0 // indirect diff --git a/go.sum b/go.sum index d46c0a8..a98110b 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,9 @@ github.com/go-resty/resty/v2 v2.11.0 h1:i7jMfNOJYMp69lq7qozJP+bjgzfAzeOhuGlyDrqx github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -47,3 +50,4 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/lago.go b/lago.go index 90d4fd5..285848b 100644 --- a/lago.go +++ b/lago.go @@ -3,6 +3,7 @@ package lago import ( "context" "fmt" + "net/url" "github.com/go-resty/resty/v2" ) @@ -24,6 +25,7 @@ type ClientRequest struct { UseIngestService bool Path string QueryParams map[string]string + UrlValues url.Values Result interface{} Body interface{} } @@ -108,7 +110,8 @@ func (c *Client) Get(ctx context.Context, cr *ClientRequest) (interface{}, *Erro request := c.HttpClient.R(). SetContext(ctx). SetError(&Error{}). - SetQueryParams(cr.QueryParams) + SetQueryParams(cr.QueryParams). + SetQueryParamsFromValues(cr.UrlValues) if hasResult { request.SetResult(cr.Result) diff --git a/subscription.go b/subscription.go index 9e95e65..10fee26 100644 --- a/subscription.go +++ b/subscription.go @@ -6,6 +6,7 @@ import ( "fmt" "time" + "github.com/google/go-querystring/query" "github.com/google/uuid" ) @@ -86,11 +87,11 @@ type SubscriptionTerminateInput struct { } type SubscriptionListInput struct { - ExternalCustomerID string `json:"external_customer_id,omitempty"` - PlanCode string `json:"plan_code,omitempty"` - PerPage int `json:"per_page,omitempty,string"` - Page int `json:"page,omitempty,string"` - Status []SubscriptionStatus `json:"status,omitempty"` + ExternalCustomerID string `url:"external_customer_id,omitempty"` + PlanCode string `url:"plan_code,omitempty"` + PerPage int `url:"per_page,omitempty"` + Page int `url:"page,omitempty"` + Status []SubscriptionStatus `url:"status,omitempty"` } type Subscription struct { @@ -208,20 +209,15 @@ func (sr *SubscriptionRequest) Get(ctx context.Context, subscriptionExternalId s } func (sr *SubscriptionRequest) GetList(ctx context.Context, subscriptionListInput SubscriptionListInput) (*SubscriptionResult, *Error) { - jsonQueryParams, err := json.Marshal(subscriptionListInput) + urlValues, err := query.Values(subscriptionListInput) if err != nil { return nil, &Error{Err: err} } - queryParams := make(map[string]string) - if err = json.Unmarshal(jsonQueryParams, &queryParams); err != nil { - return nil, &Error{Err: err} - } - clientRequest := &ClientRequest{ - Path: "subscriptions", - QueryParams: queryParams, - Result: &SubscriptionResult{}, + Path: "subscriptions", + UrlValues: urlValues, + Result: &SubscriptionResult{}, } result, clientErr := sr.client.Get(ctx, clientRequest)