Skip to content

Commit

Permalink
Merge pull request #60 from matiasinsaurralde/issue-55
Browse files Browse the repository at this point in the history
Implement reference based transaction filter
  • Loading branch information
altitude authored Oct 25, 2021
2 parents d019096 + 7fdc146 commit 7ff8756
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ func NewHttpAPI(lc fx.Lifecycle, resolver *ledger.Resolver) *HttpAPI {

r.GET("/:ledger/transactions", func(c *gin.Context) {
l, _ := c.Get("ledger")
ref := c.Query("reference")

cursor, err := l.(*ledger.Ledger).FindTransactions(
query.After(c.Query("after")),
query.Account(c.Query("account")),
query.Reference(ref),
)

c.JSON(200, gin.H{
Expand Down
6 changes: 6 additions & 0 deletions ledger/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ func Destination(v string) func(*Query) {
q.Params["destination"] = v
}
}

func Reference(v string) func(*Query) {
return func(q *Query) {
q.Params["reference"] = v
}
}
6 changes: 6 additions & 0 deletions storage/postgres/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ func (s *PGStore) FindTransactions(q query.Query) (query.Cursor, error) {
))
}

if q.HasParam("reference") {
in.Where(
in.Equal("reference", q.Params["reference"]),
)
}

sb := sqlbuilder.NewSelectBuilder()
sb.Select(
"t.id",
Expand Down
6 changes: 6 additions & 0 deletions storage/sqlite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (s *SQLiteStore) FindTransactions(q query.Query) (query.Cursor, error) {
))
}

if q.HasParam("reference") {
in.Where(
in.Equal("reference", q.Params["reference"]),
)
}

sb := sqlbuilder.NewSelectBuilder()
sb.Select(
"t.id",
Expand Down

0 comments on commit 7ff8756

Please sign in to comment.