Skip to content

Commit

Permalink
fix(subscription): Handle multiple status in GetList (#210)
Browse files Browse the repository at this point in the history
* fix(subscription): Status should be a SubscriptionStatus in ListInput payload

* fix(subscription): Handle multiple status in GetList
  • Loading branch information
vincent-pochet authored Oct 15, 2024
1 parent 39ac0e1 commit cf353de
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
5 changes: 4 additions & 1 deletion lago.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lago
import (
"context"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)
Expand All @@ -24,6 +25,7 @@ type ClientRequest struct {
UseIngestService bool
Path string
QueryParams map[string]string
UrlValues url.Values
Result interface{}
Body interface{}
}
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 10 additions & 14 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

"github.com/google/go-querystring/query"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -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 []string `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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cf353de

Please sign in to comment.