Skip to content

Commit

Permalink
feat: add missing filters when listing charges
Browse files Browse the repository at this point in the history
  • Loading branch information
Jusabe Guedes authored and dojusa committed Jan 10, 2023
1 parent 6ec2827 commit 1cc3684
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions client_charges_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@ import (
"context"
"net/url"
"strconv"
"time"
)

// ListChargesRequest is the request input to the [Client.ListCharges] method.
type ListChargesRequest struct {
PageFilters
// TeamID allows to filter list of charges points by a team ID.
TeamID *int64
// ChargePointID allows to filter list of charges points by a charge point ID.

// Filter to retrieve charges with specified chargePointId.
ChargePointID *int64

// Filter to retrieve charges with specified teamId.
TeamID *int64

// Filter to retrieve charges with specified siteId.
SiteID *int64

// Filter to retrieve charges by state.
State *ChargeState

// Filter to retrieve charges by the charge authentication type, must be combined with chargeAuthId.
ChargeAuthType *ChargeAuthType

// Filter to retrieve charges by the charge authentication ID, must be combined with chargeAuthType
// Note: for type vehicleId, chargeAuthId must not include the VID: prefix.
ChargeAuthID *string

// Filter to retrieve charges where createdAt >= fromDate.
FromDate *time.Time
}

// ListChargesResponse is the response output from the [Client.ListCharges] method.
Expand All @@ -28,11 +47,26 @@ func (c *Client) ListCharges(ctx context.Context, request *ListChargesRequest) (
path := "/v1/charges"
query := url.Values{}
request.PageFilters.Apply(query)
if request.ChargePointID != nil {
query.Set("chargePointId", strconv.Itoa(int(*request.ChargePointID)))
}
if request.TeamID != nil {
query.Set("teamId", strconv.Itoa(int(*request.TeamID)))
}
if request.ChargePointID != nil {
query.Set("chargePointId", strconv.Itoa(int(*request.ChargePointID)))
if request.SiteID != nil {
query.Set("siteId", strconv.Itoa(int(*request.SiteID)))
}
if request.State != nil {
query.Set("state", string(*request.State))
}
if request.ChargeAuthType != nil {
query.Set("chargeAuthType", string(*request.ChargeAuthType))
}
if request.ChargeAuthID != nil {
query.Set("chargeAuthId", *request.ChargeAuthID)
}
if request.FromDate != nil {
query.Set("fromDate", request.FromDate.UTC().Format(time.RFC3339))
}
return doGet[ListChargesResponse](ctx, c, path, query)
}

0 comments on commit 1cc3684

Please sign in to comment.