Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor read store #615

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.10.0
github.com/uptrace/bun v1.2.6
github.com/uptrace/bun/dialect/pgdialect v1.2.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
12 changes: 12 additions & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "github.com/formancehq/ledger/internal"
- [func \(a Account\) GetAddress\(\) string](<#Account.GetAddress>)
- [type AccountMetadata](<#AccountMetadata>)
- [type AccountsVolumes](<#AccountsVolumes>)
- [type AggregatedVolumes](<#AggregatedVolumes>)
- [type BalancesByAssets](<#BalancesByAssets>)
- [type BalancesByAssetsByAccounts](<#BalancesByAssetsByAccounts>)
- [type Configuration](<#Configuration>)
Expand Down Expand Up @@ -207,6 +208,17 @@ type AccountsVolumes struct {
}
```

<a name="AggregatedVolumes"></a>
## type AggregatedVolumes



```go
type AggregatedVolumes struct {
Aggregated VolumesByAssets `bun:"aggregated,type:jsonb"`
}
```

<a name="BalancesByAssets"></a>
## type BalancesByAssets

Expand Down
18 changes: 9 additions & 9 deletions internal/api/bulking/mocks_ledger_controller_test.go

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

18 changes: 9 additions & 9 deletions internal/api/common/mocks_ledger_controller_test.go

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

22 changes: 8 additions & 14 deletions internal/api/v1/controllers_accounts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,26 @@ import (

"errors"
"github.com/formancehq/go-libs/v2/api"
"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/ledger/internal/api/common"
ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
)

func countAccounts(w http.ResponseWriter, r *http.Request) {
l := common.LedgerFromContext(r.Context())

query, err := bunpaginate.Extract[ledgercontroller.ListAccountsQuery](r, func() (*ledgercontroller.ListAccountsQuery, error) {
options, err := getPaginatedQueryOptionsOfPITFilterWithVolumes(r)
if err != nil {
return nil, err
}
options.QueryBuilder, err = buildAccountsFilterQuery(r)
if err != nil {
return nil, err
}
return pointer.For(ledgercontroller.NewListAccountsQuery(*options)), nil
})
rq, err := getResourceQuery[any](r)
if err != nil {
api.BadRequest(w, common.ErrValidation, err)
return
}

rq.Builder, err = buildAccountsFilterQuery(r)
if err != nil {
api.BadRequest(w, common.ErrValidation, err)
return
}

count, err := l.CountAccounts(r.Context(), *query)
count, err := l.CountAccounts(r.Context(), *rq)
if err != nil {
switch {
case errors.Is(err, ledgercontroller.ErrInvalidQuery{}) || errors.Is(err, ledgercontroller.ErrMissingFeature{}):
Expand Down
Loading
Loading