Skip to content

Commit 8be803f

Browse files
committed
is: Add filter support to Count RPC for EndDeviceRegistry
1 parent cedda37 commit 8be803f

9 files changed

Lines changed: 288 additions & 223 deletions

File tree

api/ttn/lorawan/v3/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,7 @@ Configuration options for static ADR.
39913991
| Field | Type | Label | Description |
39923992
| ----- | ---- | ----- | ----------- |
39933993
| `application_ids` | [`ApplicationIdentifiers`](#ttn.lorawan.v3.ApplicationIdentifiers) | | |
3994+
| `filters` | [`ListEndDevicesRequest.Filter`](#ttn.lorawan.v3.ListEndDevicesRequest.Filter) | repeated | |
39943995

39953996
#### Field Rules
39963997

api/ttn/lorawan/v3/end_device.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ message ListEndDevicesRequest {
13481348

13491349
message CountEndDevicesRequest {
13501350
ApplicationIdentifiers application_ids = 1 [(validate.rules).message.required = true];
1351+
repeated ListEndDevicesRequest.Filter filters = 2;
13511352
}
13521353

13531354
message CountEndDevicesResponse {

pkg/identityserver/bunstore/end_device_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ func (s *endDeviceStore) CountEndDevices(ctx context.Context, ids *ttnpb.Applica
439439
by = s.selectWithID(ctx, ids.GetApplicationId())
440440
}
441441

442-
selectQuery := s.newSelectModel(ctx, &EndDevice{}).Apply(by)
442+
selectQuery := s.newSelectModel(ctx, &EndDevice{}).
443+
Apply(by).
444+
Apply(selectWithFilterFromContext(ctx))
443445

444446
// Count the total number of results.
445447
count, err := selectQuery.Count(ctx)

pkg/identityserver/end_device_registry.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ func (is *IdentityServer) countEndDevices(
340340
); err != nil {
341341
return nil, err
342342
}
343+
if req.Filters != nil {
344+
for _, filter := range req.Filters {
345+
if _, ok := filter.GetField().(*ttnpb.ListEndDevicesRequest_Filter_UpdatedSince); ok {
346+
ctx = store.WithFilter(ctx, "updated_at", filter.GetUpdatedSince().AsTime().Format(time.RFC3339Nano))
347+
}
348+
}
349+
}
343350
var count uint64
344351
err := is.store.Transact(ctx, func(ctx context.Context, st store.Store) (err error) {
345352
count, err = st.CountEndDevices(ctx, req.GetApplicationIds())

pkg/ttnpb/end_device.pb.go

Lines changed: 236 additions & 222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ttnpb/end_device.pb.paths.fm.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ttnpb/end_device.pb.setters.fm.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ttnpb/end_device.pb.validate.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/js/generated/api.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16060,6 +16060,18 @@
1606016060
}
1606116061
]
1606216062
}
16063+
},
16064+
{
16065+
"name": "filters",
16066+
"description": "",
16067+
"label": "repeated",
16068+
"type": "Filter",
16069+
"longType": "ListEndDevicesRequest.Filter",
16070+
"fullType": "ttn.lorawan.v3.ListEndDevicesRequest.Filter",
16071+
"ismap": false,
16072+
"isoneof": false,
16073+
"oneofdecl": "",
16074+
"defaultValue": ""
1606316075
}
1606416076
]
1606516077
},

0 commit comments

Comments
 (0)