Skip to content

Commit

Permalink
fix: missing filter on list logs (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Feb 25, 2025
1 parent 03de826 commit 3d27fa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/storage/ledger/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,13 @@ func TestLogsList(t *testing.T) {
// Should get only the second log, as StartTime is inclusive and EndTime exclusive.
require.Len(t, cursor.Data, 1)
require.EqualValues(t, 2, *cursor.Data[0].ID)

cursor, err = store.Logs().Paginate(context.Background(), ledgercontroller.ColumnPaginatedQuery[any]{
PageSize: 10,
Options: ledgercontroller.ResourceQuery[any]{
Builder: query.Lt("id", 3),
},
})
require.NoError(t, err)
require.Equal(t, 2, len(cursor.Data))
}
5 changes: 4 additions & 1 deletion internal/storage/ledger/resource_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func (h logsResourceHandler) filters() []filter {
// todo: add validators
name: "date",
},
{
name: "id",
},
}
}

Expand All @@ -27,7 +30,7 @@ func (h logsResourceHandler) buildDataset(store *Store, _ repositoryHandlerBuild

func (h logsResourceHandler) resolveFilter(_ *Store, _ ledgercontroller.ResourceQuery[any], operator, property string, value any) (string, []any, error) {
switch {
case property == "date":
case property == "date" || property == "id":
return fmt.Sprintf("%s %s ?", property, convertOperatorToSQL(operator)), []any{value}, nil
default:
return "", nil, fmt.Errorf("unknown key '%s' when building query", property)
Expand Down

0 comments on commit 3d27fa0

Please sign in to comment.