Skip to content

Commit

Permalink
Merge pull request #3 from bsm/feature/filter-pending
Browse files Browse the repository at this point in the history
Allow to filter pending
  • Loading branch information
dim authored Apr 25, 2019
2 parents 8c812d6 + cb757c6 commit d3779c5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 46 deletions.
8 changes: 8 additions & 0 deletions backend/internal/testdata/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ func BehavesLikeBackend(data *BehavesLikeBackendData) func() {
})).To(Ω.Succeed())
Ω.Expect(results).To(Ω.HaveLen(2))

// List pending
results = results[:0]
Ω.Expect(subject.List(ctx, &rpc.ListRequest{Filter: &rpc.ListRequest_Filter{Status: rpc.ListRequest_Filter_PENDING}}, func(h *backend.HandleData) error {
results = append(results, h)
return nil
})).To(Ω.Succeed())
Ω.Expect(results).To(Ω.HaveLen(1))

// With namespace
results = results[:0]
Ω.Expect(subject.List(ctx, &rpc.ListRequest{Filter: &rpc.ListRequest_Filter{Prefix: "a/b"}}, func(h *backend.HandleData) error {
Expand Down
2 changes: 2 additions & 0 deletions backend/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (*Backend) Close() error { return nil }
func isSelected(filter *rpc.ListRequest_Filter, handle *backend.HandleData) bool {
if filter.Status == rpc.ListRequest_Filter_DONE && !handle.IsDone() {
return false
} else if filter.Status == rpc.ListRequest_Filter_PENDING && handle.IsDone() {
return false
}

if filter.Prefix != "" && !strings.HasPrefix(handle.Namespace, filter.Prefix) {
Expand Down
2 changes: 2 additions & 0 deletions backend/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (b *postgres) List(ctx context.Context, req *rpc.ListRequest, iter backend.
if f := req.GetFilter(); f != nil {
if f.Status == rpc.ListRequest_Filter_DONE {
stmt = stmt.Where(sq.NotEq{"done_at": nil})
} else if f.Status == rpc.ListRequest_Filter_PENDING {
stmt = stmt.Where(sq.Eq{"done_at": nil})
}
if f.Prefix != "" {
stmt = stmt.Where(sq.Like{"namespace": f.Prefix + "%"})
Expand Down
96 changes: 50 additions & 46 deletions rpc/accord.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/accord.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ message ListRequest {
enum Status {
ALL = 0;
DONE = 1;
PENDING = 2;
}

// Namespace prefix.
Expand Down

0 comments on commit d3779c5

Please sign in to comment.