Skip to content

Commit

Permalink
recordstore/filter: Convert int64 param to any underlying int variati…
Browse files Browse the repository at this point in the history
…on (#90)

* recordstore/filter: Change from int param to any underlying int (variations) type

* add int8 and int16
  • Loading branch information
andrewwormald authored Feb 5, 2025
1 parent f648db8 commit 98deb76
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adapters/adaptertest/recordstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByStatus(int64(status)),
workflow.FilterByStatus(status),
)
require.Nil(t, err)
require.Equal(t, count, len(ls))
Expand Down Expand Up @@ -360,7 +360,7 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByStatus(int64(status)),
workflow.FilterByStatus(status),
)
require.Nil(t, err)
require.Equal(t, count, len(ls))
Expand Down
2 changes: 1 addition & 1 deletion adapters/webui/internal/api/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func List(listRecords ListWorkflowRecords, stringer Stringer) http.HandlerFunc {
}

if req.FilterByStatus != 0 {
filters = append(filters, workflow.FilterByStatus(int64(req.FilterByStatus)))
filters = append(filters, workflow.FilterByStatus(req.FilterByStatus))
}

list, err := listRecords(r.Context(), req.WorkflowName, req.Offset, req.Limit, order, filters...)
Expand Down
8 changes: 5 additions & 3 deletions filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package workflow

import "strconv"
import (
"strconv"
)

func MakeFilter(filters ...RecordFilter) *recordFilters {
var rf recordFilters
Expand Down Expand Up @@ -49,9 +51,9 @@ func FilterByForeignID(val string) RecordFilter {
}
}

func FilterByStatus(status int64) RecordFilter {
func FilterByStatus[statusType ~int | ~int8 | ~int16 | ~int32 | ~int64](status statusType) RecordFilter {
return func(filters *recordFilters) {
i := strconv.FormatInt(status, 10)
i := strconv.FormatInt(int64(status), 10)
filters.byStatus = makeFilterValue(i)
}
}
Expand Down

0 comments on commit 98deb76

Please sign in to comment.