Skip to content

Commit

Permalink
feat: Updates User List to support created_at & last_active_at date f…
Browse files Browse the repository at this point in the history
…ilters (#348)

* Updates User List to support created_at & last_active_at date filters

* Adds Changelog entry

* Update header to be next release

This work has yet to be released. When we cut a release, we will update
the changelog header to be the release number.
  • Loading branch information
BrandonRomano authored Oct 31, 2024
1 parent 9e781f8 commit a3db65d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Next release

- Add `EmailAddressQuery`, `PhoneNumberQuery` and `UsernameQuery` to `user.ListParams`.

## 2.1.0

- Add support for sign in tokens API operations.
Expand All @@ -15,6 +19,7 @@
## 2.0.9

## 2.0.4

- Add `IgnoreDotsForGmailAddresses` field to `InstanceRestrictions` and `instancesettings.UpdateRestrictionsParams` (#293).

## 2.0.0
Expand Down
22 changes: 20 additions & 2 deletions user/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,14 @@ type ListParams struct {
// OrganizationIDs filters users that have memberships to the given organizations. For each organization ID, the
// + and - can be prepended to the ID, which denote whether the respective organization should be included or
// excluded from the result set. Accepts up to 100 organization IDs.
OrganizationIDs []string `json:"organization_id,omitempty"`
LastActiveAtSince *int64 `json:"last_active_at_since,omitempty"`
OrganizationIDs []string `json:"organization_id,omitempty"`
// Deprecated: Prefer using the LastActiveAtAfter parameter, which has
// identical functionality. This parameter is just being renamed.
LastActiveAtSince *int64 `json:"last_active_at_since,omitempty"`
CreatedAtBefore *int64 `json:"created_at_before,omitempty"`
CreatedAtAfter *int64 `json:"created_at_after,omitempty"`
LastActiveAtBefore *int64 `json:"last_active_at_before,omitempty"`
LastActiveAtAfter *int64 `json:"last_active_at_after,omitempty"`
}

// ToQuery returns url.Values from the params.
Expand Down Expand Up @@ -269,6 +275,18 @@ func (params *ListParams) ToQuery() url.Values {
if params.LastActiveAtSince != nil {
q.Add("last_active_at_since", strconv.FormatInt(*params.LastActiveAtSince, 10))
}
if params.CreatedAtBefore != nil {
q.Add("created_at_before", strconv.FormatInt(*params.CreatedAtBefore, 10))
}
if params.CreatedAtAfter != nil {
q.Add("created_at_after", strconv.FormatInt(*params.CreatedAtAfter, 10))
}
if params.LastActiveAtBefore != nil {
q.Add("last_active_at_before", strconv.FormatInt(*params.LastActiveAtBefore, 10))
}
if params.LastActiveAtAfter != nil {
q.Add("last_active_at_after", strconv.FormatInt(*params.LastActiveAtAfter, 10))
}
return q
}

Expand Down
20 changes: 14 additions & 6 deletions user/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ func TestUserClientList_Request(t *testing.T) {
T: t,
Method: http.MethodGet,
Query: &url.Values{
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"email_address": []string{"[email protected]", "[email protected]"},
"organization_id": []string{"org_123", "org_456"},
"email_address_query": []string{"@bar.com"},
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"email_address": []string{"[email protected]", "[email protected]"},
"organization_id": []string{"org_123", "org_456"},
"email_address_query": []string{"@bar.com"},
"created_at_before": []string{"1730333164378"},
"created_at_after": []string{"1730333164378"},
"last_active_at_before": []string{"1730333164378"},
"last_active_at_after": []string{"1730333164378"},
},
},
}
Expand All @@ -65,6 +69,10 @@ func TestUserClientList_Request(t *testing.T) {
}
params.Limit = clerk.Int64(1)
params.Offset = clerk.Int64(2)
params.CreatedAtBefore = clerk.Int64(1730333164378)
params.CreatedAtAfter = clerk.Int64(1730333164378)
params.LastActiveAtBefore = clerk.Int64(1730333164378)
params.LastActiveAtAfter = clerk.Int64(1730333164378)
_, err := client.List(context.Background(), params)
require.NoError(t, err)
}
Expand Down

0 comments on commit a3db65d

Please sign in to comment.