doc-381 #384
@@ -13,7 +13,7 @@ require (
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@@ -39,16 +39,14 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -53,8 +53,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -93,8 +93,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -132,8 +130,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -199,8 +195,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,27 +9,28 @@ replace github.com/tech/sendico/fx/oracle => ../../fx/oracle
|
||||
require (
|
||||
github.com/tech/sendico/fx/oracle v0.0.0
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
"github.com/tech/sendico/billing/fees/storage/model"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type planFinder interface {
|
||||
FindActiveOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error)
|
||||
FindActiveOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error)
|
||||
FindActiveGlobalPlan(ctx context.Context, at time.Time) (*model.FeePlan, error)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func New(plans storage.PlansStore, logger *zap.Logger) *feeResolver {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) {
|
||||
func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *bson.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) {
|
||||
if r.plans == nil {
|
||||
return nil, nil, merrors.InvalidArgument("fees: plans store is required")
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.Obje
|
||||
return plan, rule, nil
|
||||
}
|
||||
|
||||
func (r *feeResolver) getOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (r *feeResolver) getOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
if r.finder != nil {
|
||||
return r.finder.FindActiveOrgPlan(ctx, orgRef, at)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (r *feeResolver) getGlobalPlan(ctx context.Context, at time.Time) (*model.F
|
||||
return r.finder.FindActiveGlobalPlan(ctx, at)
|
||||
}
|
||||
// Treat zero ObjectID as global in legacy path.
|
||||
return r.plans.GetActivePlan(ctx, primitive.NilObjectID, at)
|
||||
return r.plans.GetActivePlan(ctx, bson.NilObjectID, at)
|
||||
}
|
||||
|
||||
func selectRule(plan *model.FeePlan, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeeRule, error) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/billing/fees/storage"
|
||||
"github.com/tech/sendico/billing/fees/storage/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestResolver_GlobalFallbackWhenOrgMissing(t *testing.T) {
|
||||
store := &memoryPlansStore{plans: []*model.FeePlan{globalPlan}}
|
||||
resolver := New(store, zap.NewNop())
|
||||
|
||||
orgA := primitive.NewObjectID()
|
||||
orgA := bson.NewObjectID()
|
||||
plan, rule, err := resolver.ResolveFeeRule(context.Background(), &orgA, model.TriggerCapture, now, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("expected fallback to global, got error: %v", err)
|
||||
@@ -44,7 +44,7 @@ func TestResolver_OrgOverridesGlobal(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Now()
|
||||
org := primitive.NewObjectID()
|
||||
org := bson.NewObjectID()
|
||||
globalPlan := &model.FeePlan{
|
||||
Active: true,
|
||||
EffectiveFrom: now.Add(-time.Hour),
|
||||
@@ -71,7 +71,7 @@ func TestResolver_OrgOverridesGlobal(t *testing.T) {
|
||||
t.Fatalf("expected org rule, got %s", rule.RuleID)
|
||||
}
|
||||
|
||||
otherOrg := primitive.NewObjectID()
|
||||
otherOrg := bson.NewObjectID()
|
||||
_, rule, err = resolver.ResolveFeeRule(context.Background(), &otherOrg, model.TriggerCapture, now, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("expected global fallback for other org, got error: %v", err)
|
||||
@@ -85,7 +85,7 @@ func TestResolver_SelectsHighestPriority(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Now()
|
||||
org := primitive.NewObjectID()
|
||||
org := bson.NewObjectID()
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
EffectiveFrom: now.Add(-time.Hour),
|
||||
@@ -124,7 +124,7 @@ func TestResolver_EffectiveDateFiltering(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Now()
|
||||
org := primitive.NewObjectID()
|
||||
org := bson.NewObjectID()
|
||||
past := now.Add(-24 * time.Hour)
|
||||
future := now.Add(24 * time.Hour)
|
||||
|
||||
@@ -253,7 +253,7 @@ func TestResolver_MultipleActivePlansConflict(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Now()
|
||||
org := primitive.NewObjectID()
|
||||
org := bson.NewObjectID()
|
||||
p1 := &model.FeePlan{
|
||||
Active: true,
|
||||
EffectiveFrom: now.Add(-time.Hour),
|
||||
@@ -285,11 +285,11 @@ type memoryPlansStore struct {
|
||||
|
||||
func (m *memoryPlansStore) Create(context.Context, *model.FeePlan) error { return nil }
|
||||
func (m *memoryPlansStore) Update(context.Context, *model.FeePlan) error { return nil }
|
||||
func (m *memoryPlansStore) Get(context.Context, primitive.ObjectID) (*model.FeePlan, error) {
|
||||
func (m *memoryPlansStore) Get(context.Context, bson.ObjectID) (*model.FeePlan, error) {
|
||||
return nil, storage.ErrFeePlanNotFound
|
||||
}
|
||||
|
||||
func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
if !orgRef.IsZero() {
|
||||
if plan, err := m.FindActiveOrgPlan(ctx, orgRef, at); err == nil {
|
||||
return plan, nil
|
||||
@@ -300,7 +300,7 @@ func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef primitive.O
|
||||
return m.FindActiveGlobalPlan(ctx, at)
|
||||
}
|
||||
|
||||
func (m *memoryPlansStore) FindActiveOrgPlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (m *memoryPlansStore) FindActiveOrgPlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
var matches []*model.FeePlan
|
||||
for _, plan := range m.plans {
|
||||
if plan == nil || plan.OrganizationRef == nil || plan.OrganizationRef.IsZero() || (*plan.OrganizationRef != orgRef) {
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/billing/fees/storage/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// FeeResolver centralises plan/rule resolution with org override and global fallback.
|
||||
// Implementations live under the internal/resolver package.
|
||||
type FeeResolver interface {
|
||||
ResolveFeeRule(ctx context.Context, orgID *primitive.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error)
|
||||
ResolveFeeRule(ctx context.Context, orgID *bson.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
|
||||
tracev1 "github.com/tech/sendico/pkg/proto/common/trace/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -151,7 +151,7 @@ func (s *Service) QuoteFees(ctx context.Context, req *feesv1.QuoteFeesRequest) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orgRef, parseErr := primitive.ObjectIDFromHex(req.GetMeta().GetOrganizationRef())
|
||||
orgRef, parseErr := bson.ObjectIDFromHex(req.GetMeta().GetOrganizationRef())
|
||||
if parseErr != nil {
|
||||
logger.Warn("QuoteFees invalid organization_ref", zap.Error(parseErr))
|
||||
err = status.Error(codes.InvalidArgument, "invalid organization_ref")
|
||||
@@ -233,7 +233,7 @@ func (s *Service) PrecomputeFees(ctx context.Context, req *feesv1.PrecomputeFees
|
||||
|
||||
now := s.clock.Now()
|
||||
|
||||
orgRef, parseErr := primitive.ObjectIDFromHex(req.GetMeta().GetOrganizationRef())
|
||||
orgRef, parseErr := bson.ObjectIDFromHex(req.GetMeta().GetOrganizationRef())
|
||||
if parseErr != nil {
|
||||
logger.Warn("PrecomputeFees invalid organization_ref", zap.Error(parseErr))
|
||||
err = status.Error(codes.InvalidArgument, "invalid organization_ref")
|
||||
@@ -351,7 +351,7 @@ func (s *Service) ValidateFeeToken(ctx context.Context, req *feesv1.ValidateFeeT
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
orgRef, parseErr := primitive.ObjectIDFromHex(payload.OrganizationRef)
|
||||
orgRef, parseErr := bson.ObjectIDFromHex(payload.OrganizationRef)
|
||||
if parseErr != nil {
|
||||
resultReason = "invalid_token"
|
||||
logger.Warn("token contained invalid organization reference", zap.Error(parseErr))
|
||||
@@ -408,11 +408,11 @@ func (s *Service) validatePrecomputeRequest(req *feesv1.PrecomputeFeesRequest) e
|
||||
return s.validateQuoteRequest(&feesv1.QuoteFeesRequest{Meta: req.GetMeta(), Intent: req.GetIntent()})
|
||||
}
|
||||
|
||||
func (s *Service) computeQuote(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, overrides *feesv1.PolicyOverrides, trace *tracev1.TraceContext) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) {
|
||||
func (s *Service) computeQuote(ctx context.Context, orgRef bson.ObjectID, intent *feesv1.Intent, overrides *feesv1.PolicyOverrides, trace *tracev1.TraceContext) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) {
|
||||
return s.computeQuoteWithTime(ctx, orgRef, intent, overrides, trace, s.clock.Now())
|
||||
}
|
||||
|
||||
func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, _ *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) {
|
||||
func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef bson.ObjectID, intent *feesv1.Intent, _ *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) {
|
||||
bookedAt := now
|
||||
if intent.GetBookedAt() != nil && intent.GetBookedAt().IsValid() {
|
||||
bookedAt = intent.GetBookedAt().AsTime()
|
||||
@@ -428,7 +428,7 @@ func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.Obj
|
||||
logFields = append(logFields, logFieldsFromTrace(trace)...)
|
||||
logger := s.logger.With(logFields...)
|
||||
|
||||
var orgPtr *primitive.ObjectID
|
||||
var orgPtr *bson.ObjectID
|
||||
if !orgRef.IsZero() {
|
||||
orgPtr = &orgRef
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
tracev1 "github.com/tech/sendico/pkg/proto/common/trace/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ func TestQuoteFees_ComputesDerivedLines(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Date(2024, 1, 10, 16, 0, 0, 0, time.UTC)
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
@@ -48,7 +48,7 @@ func TestQuoteFees_ComputesDerivedLines(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
plan.SetID(primitive.NewObjectID())
|
||||
plan.SetID(bson.NewObjectID())
|
||||
plan.OrganizationRef = &orgRef
|
||||
|
||||
service := NewService(
|
||||
@@ -123,7 +123,7 @@ func TestQuoteFees_FiltersByAttributesAndDates(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Date(2024, 5, 20, 9, 30, 0, 0, time.UTC)
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
@@ -162,7 +162,7 @@ func TestQuoteFees_FiltersByAttributesAndDates(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
plan.SetID(primitive.NewObjectID())
|
||||
plan.SetID(bson.NewObjectID())
|
||||
plan.OrganizationRef = &orgRef
|
||||
|
||||
service := NewService(
|
||||
@@ -205,7 +205,7 @@ func TestQuoteFees_RoundingDown(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Date(2024, 3, 15, 12, 0, 0, 0, time.UTC)
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
@@ -223,7 +223,7 @@ func TestQuoteFees_RoundingDown(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
plan.SetID(primitive.NewObjectID())
|
||||
plan.SetID(bson.NewObjectID())
|
||||
plan.OrganizationRef = &orgRef
|
||||
|
||||
service := NewService(
|
||||
@@ -261,7 +261,7 @@ func TestQuoteFees_UsesInjectedCalculator(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Date(2024, 6, 1, 8, 0, 0, 0, time.UTC)
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
EffectiveFrom: now.Add(-time.Hour),
|
||||
@@ -276,7 +276,7 @@ func TestQuoteFees_UsesInjectedCalculator(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
plan.SetID(primitive.NewObjectID())
|
||||
plan.SetID(bson.NewObjectID())
|
||||
plan.OrganizationRef = &orgRef
|
||||
|
||||
result := &types.CalculationResult{
|
||||
@@ -334,7 +334,7 @@ func TestQuoteFees_PopulatesFxUsed(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
now := time.Date(2024, 7, 1, 9, 30, 0, 0, time.UTC)
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
plan := &model.FeePlan{
|
||||
Active: true,
|
||||
@@ -352,7 +352,7 @@ func TestQuoteFees_PopulatesFxUsed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
plan.SetID(primitive.NewObjectID())
|
||||
plan.SetID(bson.NewObjectID())
|
||||
plan.OrganizationRef = &orgRef
|
||||
|
||||
fakeOracle := &oracleclient.Fake{
|
||||
@@ -433,11 +433,11 @@ func (s *stubPlansStore) Update(context.Context, *model.FeePlan) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubPlansStore) Get(context.Context, primitive.ObjectID) (*model.FeePlan, error) {
|
||||
func (s *stubPlansStore) Get(context.Context, bson.ObjectID) (*model.FeePlan, error) {
|
||||
return nil, storage.ErrFeePlanNotFound
|
||||
}
|
||||
|
||||
func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
if !orgRef.IsZero() {
|
||||
if plan, err := s.FindActiveOrgPlan(context.Background(), orgRef, at); err == nil {
|
||||
return plan, nil
|
||||
@@ -448,7 +448,7 @@ func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef primitive.Objec
|
||||
return s.FindActiveGlobalPlan(context.Background(), at)
|
||||
}
|
||||
|
||||
func (s *stubPlansStore) FindActiveOrgPlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (s *stubPlansStore) FindActiveOrgPlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
if s.plan == nil {
|
||||
return nil, storage.ErrFeePlanNotFound
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,12 +28,12 @@ const (
|
||||
type FeePlan struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
model.Describable `bson:",inline" json:",inline"`
|
||||
OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"`
|
||||
Active bool `bson:"active" json:"active"`
|
||||
EffectiveFrom time.Time `bson:"effectiveFrom" json:"effectiveFrom"`
|
||||
EffectiveTo *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"`
|
||||
Rules []FeeRule `bson:"rules,omitempty" json:"rules,omitempty"`
|
||||
Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
|
||||
OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"`
|
||||
Active bool `bson:"active" json:"active"`
|
||||
EffectiveFrom time.Time `bson:"effectiveFrom" json:"effectiveFrom"`
|
||||
EffectiveTo *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"`
|
||||
Rules []FeeRule `bson:"rules,omitempty" json:"rules,omitempty"`
|
||||
Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// Collection implements storable.Storable.
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
m "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -112,7 +112,7 @@ func (p *plansStore) Update(ctx context.Context, plan *model.FeePlan) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *plansStore) Get(ctx context.Context, planRef primitive.ObjectID) (*model.FeePlan, error) {
|
||||
func (p *plansStore) Get(ctx context.Context, planRef bson.ObjectID) (*model.FeePlan, error) {
|
||||
if planRef.IsZero() {
|
||||
return nil, merrors.InvalidArgument("plansStore: zero plan reference")
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (p *plansStore) Get(ctx context.Context, planRef primitive.ObjectID) (*mode
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *plansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (p *plansStore) GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
// Compatibility shim: prefer org plan, fall back to global; allow zero org to mean global.
|
||||
if orgRef.IsZero() {
|
||||
return p.FindActiveGlobalPlan(ctx, at)
|
||||
@@ -142,7 +142,7 @@ func (p *plansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (p *plansStore) FindActiveOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
func (p *plansStore) FindActiveOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) {
|
||||
if orgRef.IsZero() {
|
||||
return nil, merrors.InvalidArgument("plansStore: zero organization reference")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/billing/fees/storage/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type storageError string
|
||||
@@ -33,7 +33,7 @@ type Repository interface {
|
||||
type PlansStore interface {
|
||||
Create(ctx context.Context, plan *model.FeePlan) error
|
||||
Update(ctx context.Context, plan *model.FeePlan) error
|
||||
Get(ctx context.Context, planRef primitive.ObjectID) (*model.FeePlan, error)
|
||||
Get(ctx context.Context, planRef bson.ObjectID) (*model.FeePlan, error)
|
||||
// Legacy helper that now prefers an org plan and falls back to a global plan.
|
||||
GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error)
|
||||
GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error)
|
||||
}
|
||||
|
||||
@@ -17,15 +17,13 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
@@ -37,7 +35,7 @@ require (
|
||||
github.com/xdg-go/scram v1.2.0 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
go.mongodb.org/mongo-driver v1.17.8 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
golang.org/x/crypto v0.47.0 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -22,15 +22,13 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
@@ -42,7 +40,7 @@ require (
|
||||
github.com/xdg-go/scram v1.2.0 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
go.mongodb.org/mongo-driver v1.17.8 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
golang.org/x/crypto v0.47.0 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -11,7 +11,7 @@ require (
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/tech/sendico/fx/storage v0.0.0
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -23,15 +23,13 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type quoteComputation struct {
|
||||
@@ -179,7 +179,7 @@ func buildQuoteMeta(meta *oraclev1.RequestMeta) *model.QuoteMeta {
|
||||
qm.IdempotencyKey = strings.TrimSpace(trace.GetIdempotencyKey())
|
||||
}
|
||||
if org := strings.TrimSpace(meta.GetOrganizationRef()); org != "" {
|
||||
if objID, err := primitive.ObjectIDFromHex(org); err == nil {
|
||||
if objID, err := bson.ObjectIDFromHex(org); err == nil {
|
||||
qm.SetOrganizationRef(objID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ replace github.com/tech/sendico/pkg => ../../pkg
|
||||
|
||||
require (
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
)
|
||||
|
||||
@@ -14,12 +14,10 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.2.0 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
|
||||
@@ -12,8 +12,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
|
||||
@@ -45,8 +45,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
|
||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -75,8 +73,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
@@ -118,8 +114,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestCurrencyStoreUpsertUpdate(t *testing.T) {
|
||||
repo := &repoStub{
|
||||
findOneFn: func(_ context.Context, _ builder.Query, result storable.Storable) error {
|
||||
currency := result.(*model.Currency)
|
||||
currency.SetID(primitive.NewObjectID())
|
||||
currency.SetID(bson.NewObjectID())
|
||||
currency.Code = "USD"
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestPairStoreUpsertUpdate(t *testing.T) {
|
||||
repo := &repoStub{
|
||||
findOneFn: func(_ context.Context, _ builder.Query, result storable.Storable) error {
|
||||
pair := result.(*model.Pair)
|
||||
pair.SetID(primitive.NewObjectID())
|
||||
pair.SetID(bson.NewObjectID())
|
||||
return nil
|
||||
},
|
||||
updateFn: func(_ context.Context, obj storable.Storable) error {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestRatesStoreUpsertInsert(t *testing.T) {
|
||||
|
||||
func TestRatesStoreUpsertUpdate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
existingID := primitive.NewObjectID()
|
||||
existingID := bson.NewObjectID()
|
||||
var updated *model.RateSnapshot
|
||||
|
||||
repo := &repoStub{
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type repoStub struct {
|
||||
@@ -44,7 +44,7 @@ func (r *repoStub) InsertMany(ctx context.Context, objects []storable.Storable)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repoStub) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
func (r *repoStub) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
return merrors.NotImplemented("Get not used")
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (r *repoStub) Update(ctx context.Context, obj storable.Storable) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repoStub) Patch(ctx context.Context, id primitive.ObjectID, patch builder.Patch) error {
|
||||
func (r *repoStub) Patch(ctx context.Context, id bson.ObjectID, patch builder.Patch) error {
|
||||
return merrors.NotImplemented("Patch not used")
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (r *repoStub) PatchMany(ctx context.Context, filter builder.Query, patch bu
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (r *repoStub) Delete(ctx context.Context, id primitive.ObjectID) error {
|
||||
func (r *repoStub) Delete(ctx context.Context, id bson.ObjectID) error {
|
||||
return merrors.NotImplemented("Delete not used")
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (r *repoStub) CreateIndex(def *ri.Definition) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repoStub) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) {
|
||||
func (r *repoStub) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) {
|
||||
return nil, merrors.NotImplemented("ListIDs not used")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type mongoTransactionFactory struct {
|
||||
@@ -26,7 +26,7 @@ func (t *mongoTransaction) Execute(ctx context.Context, cb transaction.Callback)
|
||||
}
|
||||
defer session.EndSession(ctx)
|
||||
|
||||
run := func(sessCtx mongo.SessionContext) (any, error) {
|
||||
run := func(sessCtx context.Context) (any, error) {
|
||||
return cb(sessCtx)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ require (
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -28,7 +28,7 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/consensys/gnark-crypto v0.19.2 // indirect
|
||||
@@ -41,7 +41,6 @@ require (
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
@@ -58,7 +57,6 @@ require (
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -22,8 +22,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -201,8 +201,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -294,8 +292,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||
ichainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -297,10 +297,10 @@ func (w *inMemoryWallets) Create(ctx context.Context, wallet *model.ManagedWalle
|
||||
}
|
||||
|
||||
if wallet.WalletRef == "" {
|
||||
wallet.WalletRef = primitive.NewObjectID().Hex()
|
||||
wallet.WalletRef = bson.NewObjectID().Hex()
|
||||
}
|
||||
if wallet.GetID() == nil || wallet.GetID().IsZero() {
|
||||
wallet.SetID(primitive.NewObjectID())
|
||||
wallet.SetID(bson.NewObjectID())
|
||||
} else {
|
||||
wallet.Update()
|
||||
}
|
||||
@@ -350,7 +350,7 @@ func (w *inMemoryWallets) List(ctx context.Context, filter model.ManagedWalletFi
|
||||
|
||||
startIndex := 0
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
for idx, item := range items {
|
||||
if item.ID.Timestamp().After(oid.Timestamp()) {
|
||||
startIndex = idx
|
||||
@@ -394,7 +394,7 @@ func (w *inMemoryWallets) SaveBalance(ctx context.Context, balance *model.Wallet
|
||||
existing, ok := w.balances[balance.WalletRef]
|
||||
if !ok {
|
||||
if balance.GetID() == nil || balance.GetID().IsZero() {
|
||||
balance.SetID(primitive.NewObjectID())
|
||||
balance.SetID(bson.NewObjectID())
|
||||
}
|
||||
w.balances[balance.WalletRef] = balance
|
||||
return nil
|
||||
@@ -446,10 +446,10 @@ func (t *inMemoryTransfers) Create(ctx context.Context, transfer *model.Transfer
|
||||
return t.items[ref], merrors.ErrDataConflict
|
||||
}
|
||||
if transfer.TransferRef == "" {
|
||||
transfer.TransferRef = primitive.NewObjectID().Hex()
|
||||
transfer.TransferRef = bson.NewObjectID().Hex()
|
||||
}
|
||||
if transfer.GetID() == nil || transfer.GetID().IsZero() {
|
||||
transfer.SetID(primitive.NewObjectID())
|
||||
transfer.SetID(bson.NewObjectID())
|
||||
} else {
|
||||
transfer.Update()
|
||||
}
|
||||
@@ -491,7 +491,7 @@ func (t *inMemoryTransfers) List(ctx context.Context, filter model.TransferFilte
|
||||
|
||||
start := 0
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
for idx, item := range items {
|
||||
if item.ID.Timestamp().After(oid.Timestamp()) {
|
||||
start = idx
|
||||
@@ -573,7 +573,7 @@ func (d *inMemoryDeposits) Record(ctx context.Context, deposit *model.Deposit) e
|
||||
return nil
|
||||
}
|
||||
if deposit.GetID() == nil || deposit.GetID().IsZero() {
|
||||
deposit.SetID(primitive.NewObjectID())
|
||||
deposit.SetID(bson.NewObjectID())
|
||||
}
|
||||
if deposit.ObservedAt.IsZero() {
|
||||
deposit.ObservedAt = time.Now().UTC()
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
chainasset "github.com/tech/sendico/pkg/chain"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// CloneMoney defensively copies a Money proto.
|
||||
@@ -42,11 +42,11 @@ func ResolveContractAddress(tokens []TokenContract, symbol string) string {
|
||||
}
|
||||
|
||||
func GenerateWalletRef() string {
|
||||
return primitive.NewObjectID().Hex()
|
||||
return bson.NewObjectID().Hex()
|
||||
}
|
||||
|
||||
func GenerateTransferRef() string {
|
||||
return primitive.NewObjectID().Hex()
|
||||
return bson.NewObjectID().Hex()
|
||||
}
|
||||
|
||||
func ChainKeyFromEnum(chain chainv1.ChainNetwork) (string, chainv1.ChainNetwork) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -123,7 +123,7 @@ func (t *Transfers) List(ctx context.Context, filter model.TransferFilter) (*mod
|
||||
}
|
||||
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
query = query.Comparison(repository.IDField(), builder.Gt, oid)
|
||||
} else {
|
||||
t.logger.Warn("Ignoring invalid transfer cursor", zap.String("cursor", cursor), zap.Error(err))
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -173,7 +173,7 @@ func (w *Wallets) List(ctx context.Context, filter model.ManagedWalletFilter) (*
|
||||
}
|
||||
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
query = query.Comparison(repository.IDField(), builder.Gt, oid)
|
||||
fields = append(fields, zap.String("cursor", cursor))
|
||||
} else {
|
||||
|
||||
@@ -20,15 +20,13 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
@@ -42,7 +40,7 @@ require (
|
||||
github.com/xdg-go/scram v1.2.0 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
go.mongodb.org/mongo-driver v1.17.8 // indirect
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
golang.org/x/crypto v0.47.0 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -152,8 +148,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -6,7 +6,7 @@ replace github.com/tech/sendico/pkg => ../../pkg
|
||||
|
||||
require (
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -18,16 +18,14 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type PaymentStatus string
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
type PaymentRecord struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||
IdempotencyKey string `bson:"idempotencyKey,omitempty" json:"idempotency_key,omitempty"`
|
||||
PaymentIntentID string `bson:"paymentIntentId,omitempty" json:"payment_intent_id,omitempty"`
|
||||
QuoteRef string `bson:"quoteRef,omitempty" json:"quote_ref,omitempty"`
|
||||
@@ -34,7 +34,7 @@ type PaymentRecord struct {
|
||||
}
|
||||
|
||||
type TelegramConfirmation struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||
RequestID string `bson:"requestId,omitempty" json:"request_id,omitempty"`
|
||||
PaymentIntentID string `bson:"paymentIntentId,omitempty" json:"payment_intent_id,omitempty"`
|
||||
QuoteRef string `bson:"quoteRef,omitempty" json:"quote_ref,omitempty"`
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -12,10 +12,9 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -91,11 +90,11 @@ func (p *Payments) Upsert(ctx context.Context, record *model.PaymentRecord) erro
|
||||
record.CreatedAt = now
|
||||
}
|
||||
record.UpdatedAt = now
|
||||
record.ID = primitive.NilObjectID
|
||||
record.ID = bson.NilObjectID
|
||||
update := bson.M{
|
||||
"$set": record,
|
||||
}
|
||||
_, err := p.coll.UpdateOne(ctx, bson.M{fieldIdempotencyKey: record.IdempotencyKey}, update, options.Update().SetUpsert(true))
|
||||
_, err := p.coll.UpdateOne(ctx, bson.M{fieldIdempotencyKey: record.IdempotencyKey}, update, options.UpdateOne().SetUpsert(true))
|
||||
if err != nil {
|
||||
if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
|
||||
p.logger.Warn("Failed to upsert payment record",
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ func (t *TelegramConfirmations) Upsert(ctx context.Context, record *model.Telegr
|
||||
update := bson.M{
|
||||
"$set": record,
|
||||
}
|
||||
_, err := t.coll.UpdateOne(ctx, bson.M{fieldRequestID: record.RequestID}, update, options.Update().SetUpsert(true))
|
||||
_, err := t.coll.UpdateOne(ctx, bson.M{fieldRequestID: record.RequestID}, update, options.UpdateOne().SetUpsert(true))
|
||||
if err != nil && !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
|
||||
fields := []zap.Field{zap.String("request_id", record.RequestID)}
|
||||
if record.PaymentIntentID != "" {
|
||||
|
||||
@@ -14,7 +14,7 @@ require (
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -30,7 +30,7 @@ require (
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.6 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/consensys/gnark-crypto v0.19.2 // indirect
|
||||
@@ -44,7 +44,6 @@ require (
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
@@ -61,7 +60,6 @@ require (
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -24,8 +24,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -208,8 +208,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -309,8 +307,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||
ichainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -299,10 +299,10 @@ func (w *inMemoryWallets) Create(ctx context.Context, wallet *model.ManagedWalle
|
||||
}
|
||||
|
||||
if wallet.WalletRef == "" {
|
||||
wallet.WalletRef = primitive.NewObjectID().Hex()
|
||||
wallet.WalletRef = bson.NewObjectID().Hex()
|
||||
}
|
||||
if wallet.GetID() == nil || wallet.GetID().IsZero() {
|
||||
wallet.SetID(primitive.NewObjectID())
|
||||
wallet.SetID(bson.NewObjectID())
|
||||
} else {
|
||||
wallet.Update()
|
||||
}
|
||||
@@ -352,7 +352,7 @@ func (w *inMemoryWallets) List(ctx context.Context, filter model.ManagedWalletFi
|
||||
|
||||
startIndex := 0
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
for idx, item := range items {
|
||||
if item.ID.Timestamp().After(oid.Timestamp()) {
|
||||
startIndex = idx
|
||||
@@ -396,7 +396,7 @@ func (w *inMemoryWallets) SaveBalance(ctx context.Context, balance *model.Wallet
|
||||
existing, ok := w.balances[balance.WalletRef]
|
||||
if !ok {
|
||||
if balance.GetID() == nil || balance.GetID().IsZero() {
|
||||
balance.SetID(primitive.NewObjectID())
|
||||
balance.SetID(bson.NewObjectID())
|
||||
}
|
||||
w.balances[balance.WalletRef] = balance
|
||||
return nil
|
||||
@@ -448,10 +448,10 @@ func (t *inMemoryTransfers) Create(ctx context.Context, transfer *model.Transfer
|
||||
return t.items[ref], merrors.ErrDataConflict
|
||||
}
|
||||
if transfer.TransferRef == "" {
|
||||
transfer.TransferRef = primitive.NewObjectID().Hex()
|
||||
transfer.TransferRef = bson.NewObjectID().Hex()
|
||||
}
|
||||
if transfer.GetID() == nil || transfer.GetID().IsZero() {
|
||||
transfer.SetID(primitive.NewObjectID())
|
||||
transfer.SetID(bson.NewObjectID())
|
||||
} else {
|
||||
transfer.Update()
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (t *inMemoryTransfers) List(ctx context.Context, filter model.TransferFilte
|
||||
|
||||
start := 0
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
for idx, item := range items {
|
||||
if item.ID.Timestamp().After(oid.Timestamp()) {
|
||||
start = idx
|
||||
@@ -575,7 +575,7 @@ func (d *inMemoryDeposits) Record(ctx context.Context, deposit *model.Deposit) e
|
||||
return nil
|
||||
}
|
||||
if deposit.GetID() == nil || deposit.GetID().IsZero() {
|
||||
deposit.SetID(primitive.NewObjectID())
|
||||
deposit.SetID(bson.NewObjectID())
|
||||
}
|
||||
if deposit.ObservedAt.IsZero() {
|
||||
deposit.ObservedAt = time.Now().UTC()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// CloneMoney defensively copies a Money proto.
|
||||
@@ -43,11 +43,11 @@ func ResolveContractAddress(tokens []TokenContract, symbol string) string {
|
||||
}
|
||||
|
||||
func GenerateWalletRef() string {
|
||||
return primitive.NewObjectID().Hex()
|
||||
return bson.NewObjectID().Hex()
|
||||
}
|
||||
|
||||
func GenerateTransferRef() string {
|
||||
return primitive.NewObjectID().Hex()
|
||||
return bson.NewObjectID().Hex()
|
||||
}
|
||||
|
||||
func ChainKeyFromEnum(chain chainv1.ChainNetwork) (string, chainv1.ChainNetwork) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -123,7 +123,7 @@ func (t *Transfers) List(ctx context.Context, filter model.TransferFilter) (*mod
|
||||
}
|
||||
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
query = query.Comparison(repository.IDField(), builder.Gt, oid)
|
||||
} else {
|
||||
t.logger.Warn("Ignoring invalid transfer cursor", zap.String("cursor", cursor), zap.Error(err))
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -173,7 +173,7 @@ func (w *Wallets) List(ctx context.Context, filter model.ManagedWalletFilter) (*
|
||||
}
|
||||
|
||||
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
|
||||
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
|
||||
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
|
||||
query = query.Comparison(repository.IDField(), builder.Gt, oid)
|
||||
fields = append(fields, zap.String("cursor", cursor))
|
||||
} else {
|
||||
|
||||
@@ -1 +1 @@
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
||||
@@ -9,7 +9,7 @@ require (
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
go.mongodb.org/mongo-driver v1.17.8
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||
go.uber.org/zap v1.27.1
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -21,17 +21,15 @@ require (
|
||||
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
|
||||
github.com/casbin/casbin/v2 v2.135.0 // indirect
|
||||
github.com/casbin/govaluate v1.10.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-chi/chi/v5 v5.2.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nats-io/nats.go v1.48.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.15 // indirect
|
||||
|
||||
@@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
|
||||
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
|
||||
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
|
||||
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
|
||||
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
@@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
|
||||
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
@@ -152,8 +148,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
|
||||
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// AccountType controls normal balance side.
|
||||
@@ -35,7 +35,7 @@ type Account struct {
|
||||
Currency string `bson:"currency,omitempty" json:"currency,omitempty"`
|
||||
|
||||
// Managing entity in your platform (not legal owner).
|
||||
OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"`
|
||||
OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"`
|
||||
|
||||
// Posting policy & lifecycle
|
||||
AllowNegative bool `bson:"allowNegative" json:"allowNegative"`
|
||||
@@ -131,7 +131,7 @@ func (a *Account) BalanceSide() int {
|
||||
}
|
||||
|
||||
// CloseOwnershipPeriod sets the To date for the first matching active ownership.
|
||||
func (a *Account) CloseOwnershipPeriod(partyID primitive.ObjectID, role OwnershipRole, to time.Time) bool {
|
||||
func (a *Account) CloseOwnershipPeriod(partyID bson.ObjectID, role OwnershipRole, to time.Time) bool {
|
||||
for i := range a.Ownerships {
|
||||
o := &a.Ownerships[i]
|
||||
if o.OwnerPartyRef == partyID && o.Role == role && o.ActiveAt(to) {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package ledger
|
||||
|
||||
import (
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"github.com/shopspring/decimal"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type AccountBalance struct {
|
||||
model.PermissionBound `bson:",inline" json:",inline"`
|
||||
LedgerAccountRef primitive.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` // unique
|
||||
Balance decimal.Decimal `bson:"balance" json:"balance"`
|
||||
Version int64 `bson:"version" json:"version"` // for optimistic locking
|
||||
LedgerAccountRef bson.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` // unique
|
||||
Balance decimal.Decimal `bson:"balance" json:"balance"`
|
||||
Version int64 `bson:"version" json:"version"` // for optimistic locking
|
||||
}
|
||||
|
||||
func (a *AccountBalance) Collection() string {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// EntryType is a closed set of journal entry kinds.
|
||||
@@ -35,10 +35,10 @@ type JournalEntry struct {
|
||||
Version int64 `bson:"version" json:"version"`
|
||||
|
||||
// Denormalized set of all affected ledger accounts (for entry-level access control & queries)
|
||||
LedgerAccountRefs []primitive.ObjectID `bson:"ledgerAccountRefs,omitempty" json:"ledgerAccountRefs,omitempty"`
|
||||
LedgerAccountRefs []bson.ObjectID `bson:"ledgerAccountRefs,omitempty" json:"ledgerAccountRefs,omitempty"`
|
||||
|
||||
// Optional backlink for reversals
|
||||
ReversalOf *primitive.ObjectID `bson:"reversalOf,omitempty" json:"reversalOf,omitempty"`
|
||||
ReversalOf *bson.ObjectID `bson:"reversalOf,omitempty" json:"reversalOf,omitempty"`
|
||||
}
|
||||
|
||||
func (j *JournalEntry) Collection() string {
|
||||
|
||||
@@ -3,7 +3,7 @@ package ledger
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// OwnershipRole captures legal roles (not permissions).
|
||||
@@ -17,11 +17,11 @@ const (
|
||||
)
|
||||
|
||||
type Ownership struct {
|
||||
OwnerPartyRef primitive.ObjectID `bson:"ownerPartyRef" json:"ownerPartyRef"`
|
||||
Role OwnershipRole `bson:"role" json:"role"`
|
||||
SharePct *float64 `bson:"sharePct,omitempty" json:"sharePct,omitempty"` // 0..100; nil = unspecified
|
||||
From time.Time `bson:"effectiveFrom" json:"effectiveFrom"`
|
||||
To *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` // active if t < To; nil = open
|
||||
OwnerPartyRef bson.ObjectID `bson:"ownerPartyRef" json:"ownerPartyRef"`
|
||||
Role OwnershipRole `bson:"role" json:"role"`
|
||||
SharePct *float64 `bson:"sharePct,omitempty" json:"sharePct,omitempty"` // 0..100; nil = unspecified
|
||||
From time.Time `bson:"effectiveFrom" json:"effectiveFrom"`
|
||||
To *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` // active if t < To; nil = open
|
||||
}
|
||||
|
||||
func (o *Ownership) Validate() error {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// PartyKind (string-backed enum) — readable in BSON/JSON, safe in Go.
|
||||
@@ -39,10 +39,10 @@ func (k *PartyKind) UnmarshalJSON(b []byte) error {
|
||||
type Party struct {
|
||||
model.PermissionBound `bson:",inline" json:",inline"`
|
||||
|
||||
Kind PartyKind `bson:"kind" json:"kind"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
UserRef *primitive.ObjectID `bson:"userRef,omitempty" json:"userRef,omitempty"` // internal user, if applicable
|
||||
OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // internal org, if applicable
|
||||
Kind PartyKind `bson:"kind" json:"kind"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
UserRef *bson.ObjectID `bson:"userRef,omitempty" json:"userRef,omitempty"` // internal user, if applicable
|
||||
OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // internal org, if applicable
|
||||
// add your own fields here if needed (KYC flags, etc.)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
package ledger
|
||||
|
||||
import (
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"github.com/shopspring/decimal"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// LineType is a closed set of posting line roles within an entry.
|
||||
@@ -22,8 +22,8 @@ const (
|
||||
type PostingLine struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
|
||||
JournalEntryRef primitive.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"`
|
||||
LedgerAccountRef primitive.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"`
|
||||
JournalEntryRef bson.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"`
|
||||
LedgerAccountRef bson.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"`
|
||||
|
||||
// Amount sign convention: positive = credit, negative = debit
|
||||
Amount decimal.Decimal `bson:"amount" json:"amount"`
|
||||
|
||||
@@ -14,14 +14,14 @@ import (
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
describablev1 "github.com/tech/sendico/pkg/proto/common/describable/v1"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// createAccountParams holds validated and normalized fields from a CreateAccountRequest.
|
||||
type createAccountParams struct {
|
||||
orgRef primitive.ObjectID
|
||||
orgRef bson.ObjectID
|
||||
currency string
|
||||
modelType pmodel.LedgerAccountType
|
||||
modelStatus pmodel.LedgerAccountStatus
|
||||
@@ -104,7 +104,7 @@ func (s *Service) createAccountResponder(_ context.Context, req *ledgerv1.Create
|
||||
}
|
||||
|
||||
// resolveTopologyAccount ensures ledger topology is initialized and returns the system account for the given role.
|
||||
func (s *Service) resolveTopologyAccount(ctx context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*ledgerv1.CreateAccountResponse, error) {
|
||||
func (s *Service) resolveTopologyAccount(ctx context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*ledgerv1.CreateAccountResponse, error) {
|
||||
if err := s.ensureLedgerTopology(ctx, orgRef, currency); err != nil {
|
||||
recordAccountOperation("create", "error")
|
||||
return nil, err
|
||||
@@ -142,7 +142,7 @@ func (s *Service) persistNewAccount(ctx context.Context, p createAccountParams,
|
||||
|
||||
const maxCreateAttempts = 3
|
||||
for attempt := 0; attempt < maxCreateAttempts; attempt++ {
|
||||
accountID := primitive.NewObjectID()
|
||||
accountID := bson.NewObjectID()
|
||||
account := buildNewAccount(p, metadata, describable, ownerRef, req.GetAllowNegative(), accountID)
|
||||
|
||||
err := s.storage.Accounts().Create(ctx, account)
|
||||
@@ -180,7 +180,7 @@ func (s *Service) persistNewAccount(ctx context.Context, p createAccountParams,
|
||||
}
|
||||
|
||||
// parseOwnerRef parses an optional owner reference string into an ObjectID pointer.
|
||||
func parseOwnerRef(ownerRefStr string) (*primitive.ObjectID, error) {
|
||||
func parseOwnerRef(ownerRefStr string) (*bson.ObjectID, error) {
|
||||
if ownerRefStr == "" {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func parseOwnerRef(ownerRefStr string) (*primitive.ObjectID, error) {
|
||||
}
|
||||
|
||||
// buildNewAccount constructs a LedgerAccount model from validated parameters.
|
||||
func buildNewAccount(p createAccountParams, metadata map[string]string, describable *pmodel.Describable, ownerRef *primitive.ObjectID, allowNegative bool, accountRef primitive.ObjectID) *pmodel.LedgerAccount {
|
||||
func buildNewAccount(p createAccountParams, metadata map[string]string, describable *pmodel.Describable, ownerRef *bson.ObjectID, allowNegative bool, accountRef bson.ObjectID) *pmodel.LedgerAccount {
|
||||
account := &pmodel.LedgerAccount{
|
||||
AccountCode: generateAccountCode(p.modelType, p.currency, accountRef),
|
||||
Currency: p.currency,
|
||||
@@ -353,14 +353,14 @@ func toProtoAccount(account *pmodel.LedgerAccount) *ledgerv1.LedgerAccount {
|
||||
}
|
||||
}
|
||||
|
||||
func objectIDHex(id primitive.ObjectID) string {
|
||||
func objectIDHex(id bson.ObjectID) string {
|
||||
if id.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return id.Hex()
|
||||
}
|
||||
|
||||
func objectIDPtrHex(id *primitive.ObjectID) string {
|
||||
func objectIDPtrHex(id *bson.ObjectID) string {
|
||||
if id == nil || id.IsZero() {
|
||||
return ""
|
||||
}
|
||||
@@ -413,11 +413,11 @@ func describableToProto(desc pmodel.Describable) *describablev1.Describable {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) ensureSettlementAccount(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *Service) ensureSettlementAccount(ctx context.Context, orgRef bson.ObjectID, currency string) (*pmodel.LedgerAccount, error) {
|
||||
return s.ensureRoleAccount(ctx, orgRef, currency, pmodel.AccountRoleSettlement)
|
||||
}
|
||||
|
||||
func generateAccountCode(accountType pmodel.LedgerAccountType, currency string, id primitive.ObjectID) string {
|
||||
func generateAccountCode(accountType pmodel.LedgerAccountType, currency string, id bson.ObjectID) string {
|
||||
typePart := strings.ToLower(strings.TrimSpace(string(accountType)))
|
||||
if typePart == "" {
|
||||
typePart = "account"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
@@ -45,7 +45,7 @@ func (s *accountStoreStub) Create(_ context.Context, account *pmodel.LedgerAccou
|
||||
}
|
||||
|
||||
if account.GetID() == nil || account.GetID().IsZero() {
|
||||
account.SetID(primitive.NewObjectID())
|
||||
account.SetID(bson.NewObjectID())
|
||||
}
|
||||
|
||||
account.CreatedAt = account.CreatedAt.UTC()
|
||||
@@ -55,18 +55,18 @@ func (s *accountStoreStub) Create(_ context.Context, account *pmodel.LedgerAccou
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) GetByAccountCode(_ context.Context, _ primitive.ObjectID, _ string, _ string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) GetByAccountCode(_ context.Context, _ bson.ObjectID, _ string, _ string) (*pmodel.LedgerAccount, error) {
|
||||
if s.existingErr != nil {
|
||||
return nil, s.existingErr
|
||||
}
|
||||
return s.existing, nil
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) Get(context.Context, primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) Get(context.Context, bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) GetByRole(_ context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) GetByRole(_ context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
if s.existingByRole != nil {
|
||||
if acc, ok := s.existingByRole[role]; ok {
|
||||
return acc, nil
|
||||
@@ -84,7 +84,7 @@ func (s *accountStoreStub) GetSystemAccount(context.Context, pmodel.SystemAccoun
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
if s.defaultErr != nil {
|
||||
return nil, s.defaultErr
|
||||
}
|
||||
@@ -94,11 +94,11 @@ func (s *accountStoreStub) GetDefaultSettlement(context.Context, primitive.Objec
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
func (s *accountStoreStub) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *accountStoreStub) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
func (s *accountStoreStub) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func (r *repositoryStub) Outbox() storage.OutboxStore { return n
|
||||
func TestCreateAccountResponder_Success(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
accountStore := &accountStoreStub{}
|
||||
svc := &Service{
|
||||
@@ -161,7 +161,7 @@ func TestCreateAccountResponder_Success(t *testing.T) {
|
||||
func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
accountStore := &accountStoreStub{}
|
||||
svc := &Service{
|
||||
@@ -237,7 +237,7 @@ func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) {
|
||||
func TestCreateAccountResponder_RetriesOnConflict(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accountStore := &accountStoreStub{
|
||||
// first create attempt returns conflict, second succeeds
|
||||
createErrs: []error{merrors.DataConflict("duplicate")},
|
||||
@@ -292,7 +292,7 @@ func TestCreateAccountResponder_InvalidAccountType(t *testing.T) {
|
||||
|
||||
// AccountType missing => must fail
|
||||
req := &ledgerv1.CreateAccountRequest{
|
||||
OrganizationRef: primitive.NewObjectID().Hex(),
|
||||
OrganizationRef: bson.NewObjectID().Hex(),
|
||||
Currency: "USD",
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -50,16 +50,16 @@ func (r *memoryRepository) Outbox() storage.OutboxStore { return
|
||||
func (r *memoryRepository) TransactionFactory() transaction.Factory { return r.txFactory }
|
||||
|
||||
type memoryAccountsStore struct {
|
||||
records map[primitive.ObjectID]*pmodel.LedgerAccount
|
||||
records map[bson.ObjectID]*pmodel.LedgerAccount
|
||||
systemByPurposeKey map[string]*pmodel.LedgerAccount
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) Create(_ context.Context, account *pmodel.LedgerAccount) error {
|
||||
if account.GetID() == nil || account.GetID().IsZero() {
|
||||
account.SetID(primitive.NewObjectID())
|
||||
account.SetID(bson.NewObjectID())
|
||||
}
|
||||
if s.records == nil {
|
||||
s.records = make(map[primitive.ObjectID]*pmodel.LedgerAccount)
|
||||
s.records = make(map[bson.ObjectID]*pmodel.LedgerAccount)
|
||||
}
|
||||
s.records[*account.GetID()] = account
|
||||
if account.SystemPurpose != nil {
|
||||
@@ -72,7 +72,7 @@ func (s *memoryAccountsStore) Create(_ context.Context, account *pmodel.LedgerAc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) Get(_ context.Context, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *memoryAccountsStore) Get(_ context.Context, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
if s.records == nil {
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
@@ -82,11 +82,11 @@ func (s *memoryAccountsStore) Get(_ context.Context, accountRef primitive.Object
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *memoryAccountsStore) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by code")
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *memoryAccountsStore) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by role")
|
||||
}
|
||||
|
||||
@@ -101,15 +101,15 @@ func (s *memoryAccountsStore) GetSystemAccount(_ context.Context, purpose pmodel
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *memoryAccountsStore) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get default settlement")
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
func (s *memoryAccountsStore) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("list by organization")
|
||||
}
|
||||
|
||||
func (s *memoryAccountsStore) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
func (s *memoryAccountsStore) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
return merrors.NotImplemented("update status")
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ type memoryJournalEntriesStore struct {
|
||||
|
||||
func (s *memoryJournalEntriesStore) Create(_ context.Context, entry *model.JournalEntry) error {
|
||||
if entry.GetID() == nil || entry.GetID().IsZero() {
|
||||
entry.SetID(primitive.NewObjectID())
|
||||
entry.SetID(bson.NewObjectID())
|
||||
}
|
||||
if s.byKey == nil {
|
||||
s.byKey = make(map[string]*model.JournalEntry)
|
||||
@@ -146,11 +146,11 @@ func (s *memoryJournalEntriesStore) Create(_ context.Context, entry *model.Journ
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *memoryJournalEntriesStore) Get(context.Context, primitive.ObjectID) (*model.JournalEntry, error) {
|
||||
func (s *memoryJournalEntriesStore) Get(context.Context, bson.ObjectID) (*model.JournalEntry, error) {
|
||||
return nil, merrors.NotImplemented("get entry")
|
||||
}
|
||||
|
||||
func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRef primitive.ObjectID, key string) (*model.JournalEntry, error) {
|
||||
func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRef bson.ObjectID, key string) (*model.JournalEntry, error) {
|
||||
if s.byKey == nil {
|
||||
return nil, storage.ErrJournalEntryNotFound
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRe
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
func (s *memoryJournalEntriesStore) ListByOrganization(context.Context, primitive.ObjectID, int, int) ([]*model.JournalEntry, error) {
|
||||
func (s *memoryJournalEntriesStore) ListByOrganization(context.Context, bson.ObjectID, int, int) ([]*model.JournalEntry, error) {
|
||||
return nil, merrors.NotImplemented("list entries")
|
||||
}
|
||||
|
||||
@@ -174,19 +174,19 @@ func (s *memoryPostingLinesStore) CreateMany(_ context.Context, lines []*model.P
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *memoryPostingLinesStore) ListByJournalEntry(context.Context, primitive.ObjectID) ([]*model.PostingLine, error) {
|
||||
func (s *memoryPostingLinesStore) ListByJournalEntry(context.Context, bson.ObjectID) ([]*model.PostingLine, error) {
|
||||
return nil, merrors.NotImplemented("list lines by entry")
|
||||
}
|
||||
|
||||
func (s *memoryPostingLinesStore) ListByAccount(context.Context, primitive.ObjectID, int, int) ([]*model.PostingLine, error) {
|
||||
func (s *memoryPostingLinesStore) ListByAccount(context.Context, bson.ObjectID, int, int) ([]*model.PostingLine, error) {
|
||||
return nil, merrors.NotImplemented("list lines by account")
|
||||
}
|
||||
|
||||
type memoryBalancesStore struct {
|
||||
records map[primitive.ObjectID]*model.AccountBalance
|
||||
records map[bson.ObjectID]*model.AccountBalance
|
||||
}
|
||||
|
||||
func (s *memoryBalancesStore) Get(_ context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) {
|
||||
func (s *memoryBalancesStore) Get(_ context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
|
||||
if s.records == nil {
|
||||
return nil, storage.ErrBalanceNotFound
|
||||
}
|
||||
@@ -199,14 +199,14 @@ func (s *memoryBalancesStore) Get(_ context.Context, accountRef primitive.Object
|
||||
|
||||
func (s *memoryBalancesStore) Upsert(_ context.Context, balance *model.AccountBalance) error {
|
||||
if s.records == nil {
|
||||
s.records = make(map[primitive.ObjectID]*model.AccountBalance)
|
||||
s.records = make(map[bson.ObjectID]*model.AccountBalance)
|
||||
}
|
||||
copied := *balance
|
||||
s.records[balance.AccountRef] = &copied
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *memoryBalancesStore) IncrementBalance(context.Context, primitive.ObjectID, string) error {
|
||||
func (s *memoryBalancesStore) IncrementBalance(context.Context, bson.ObjectID, string) error {
|
||||
return merrors.NotImplemented("increment balance")
|
||||
}
|
||||
|
||||
@@ -216,13 +216,13 @@ func (memoryOutboxStore) Create(context.Context, *model.OutboxEvent) error { ret
|
||||
func (memoryOutboxStore) ListPending(context.Context, int) ([]*model.OutboxEvent, error) {
|
||||
return nil, merrors.NotImplemented("list outbox")
|
||||
}
|
||||
func (memoryOutboxStore) MarkSent(context.Context, primitive.ObjectID, time.Time) error {
|
||||
func (memoryOutboxStore) MarkSent(context.Context, bson.ObjectID, time.Time) error {
|
||||
return merrors.NotImplemented("mark sent")
|
||||
}
|
||||
func (memoryOutboxStore) MarkFailed(context.Context, primitive.ObjectID) error {
|
||||
func (memoryOutboxStore) MarkFailed(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("mark failed")
|
||||
}
|
||||
func (memoryOutboxStore) IncrementAttempts(context.Context, primitive.ObjectID) error {
|
||||
func (memoryOutboxStore) IncrementAttempts(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("increment attempts")
|
||||
}
|
||||
|
||||
@@ -242,9 +242,9 @@ func newTestService() (*Service, *memoryRepository) {
|
||||
return svc, repo
|
||||
}
|
||||
|
||||
func newOrgAccount(orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount {
|
||||
func newOrgAccount(orgRef bson.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount {
|
||||
account := &pmodel.LedgerAccount{
|
||||
AccountCode: "test:" + strings.ToLower(currency) + ":" + primitive.NewObjectID().Hex(),
|
||||
AccountCode: "test:" + strings.ToLower(currency) + ":" + bson.NewObjectID().Hex(),
|
||||
Currency: currency,
|
||||
AccountType: pmodel.LedgerAccountTypeAsset,
|
||||
Status: pmodel.LedgerAccountStatusActive,
|
||||
@@ -256,7 +256,7 @@ func newOrgAccount(orgRef primitive.ObjectID, currency string, role pmodel.Accou
|
||||
return account
|
||||
}
|
||||
|
||||
func balanceString(t *testing.T, balances *memoryBalancesStore, accountID primitive.ObjectID) string {
|
||||
func balanceString(t *testing.T, balances *memoryBalancesStore, accountID bson.ObjectID) string {
|
||||
t.Helper()
|
||||
bal, err := balances.Get(context.Background(), accountID)
|
||||
if errors.Is(err, storage.ErrBalanceNotFound) {
|
||||
@@ -266,7 +266,7 @@ func balanceString(t *testing.T, balances *memoryBalancesStore, accountID primit
|
||||
return bal.Balance
|
||||
}
|
||||
|
||||
func balanceDecimal(t *testing.T, balances *memoryBalancesStore, accountID primitive.ObjectID) decimal.Decimal {
|
||||
func balanceDecimal(t *testing.T, balances *memoryBalancesStore, accountID bson.ObjectID) decimal.Decimal {
|
||||
t.Helper()
|
||||
bal, err := balances.Get(context.Background(), accountID)
|
||||
if errors.Is(err, storage.ErrBalanceNotFound) {
|
||||
@@ -289,7 +289,7 @@ func TestExternalCreditAndDebit(t *testing.T) {
|
||||
svc, repo := newTestService()
|
||||
require.NoError(t, svc.ensureSystemAccounts(ctx))
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending)
|
||||
require.NoError(t, repo.accounts.Create(ctx, pending))
|
||||
|
||||
@@ -333,7 +333,7 @@ func TestExternalCreditCurrencyMismatch(t *testing.T) {
|
||||
svc, repo := newTestService()
|
||||
require.NoError(t, svc.ensureSystemAccounts(ctx))
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending)
|
||||
require.NoError(t, repo.accounts.Create(ctx, pending))
|
||||
|
||||
@@ -361,7 +361,7 @@ func TestExternalOperationsRejectSystemScopeTargets(t *testing.T) {
|
||||
svc, repo := newTestService()
|
||||
require.NoError(t, svc.ensureSystemAccounts(ctx))
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
source, err := repo.accounts.GetSystemAccount(ctx, pmodel.SystemAccountPurposeExternalSource, "USD")
|
||||
require.NoError(t, err)
|
||||
sink, err := repo.accounts.GetSystemAccount(ctx, pmodel.SystemAccountPurposeExternalSink, "USD")
|
||||
@@ -395,7 +395,7 @@ func TestExternalFlowInvariant(t *testing.T) {
|
||||
svc, repo := newTestService()
|
||||
require.NoError(t, svc.ensureSystemAccounts(ctx))
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending)
|
||||
transit := newOrgAccount(orgRef, "USD", pmodel.AccountRoleTransit)
|
||||
require.NoError(t, repo.accounts.Create(ctx, pending))
|
||||
@@ -441,7 +441,7 @@ func TestExternalInvariantRandomSequence(t *testing.T) {
|
||||
svc, repo := newTestService()
|
||||
require.NoError(t, svc.ensureSystemAccounts(ctx))
|
||||
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending)
|
||||
transit := newOrgAccount(orgRef, "USD", pmodel.AccountRoleTransit)
|
||||
require.NoError(t, repo.accounts.Create(ctx, pending))
|
||||
|
||||
@@ -9,18 +9,18 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// parseObjectID converts a hex string to ObjectID
|
||||
func parseObjectID(hexID string) (primitive.ObjectID, error) {
|
||||
func parseObjectID(hexID string) (bson.ObjectID, error) {
|
||||
if hexID == "" {
|
||||
return primitive.NilObjectID, merrors.InvalidArgument("empty object ID")
|
||||
return bson.NilObjectID, merrors.InvalidArgument("empty object ID")
|
||||
}
|
||||
oid, err := primitive.ObjectIDFromHex(hexID)
|
||||
oid, err := bson.ObjectIDFromHex(hexID)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, merrors.InvalidArgument(fmt.Sprintf("invalid object ID: %v", err))
|
||||
return bson.NilObjectID, merrors.InvalidArgument(fmt.Sprintf("invalid object ID: %v", err))
|
||||
}
|
||||
return oid, nil
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func TestParseObjectID(t *testing.T) {
|
||||
t.Run("ValidObjectID", func(t *testing.T) {
|
||||
validID := primitive.NewObjectID()
|
||||
validID := bson.NewObjectID()
|
||||
result, err := parseObjectID(validID.Hex())
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -27,7 +27,7 @@ func TestParseObjectID(t *testing.T) {
|
||||
result, err := parseObjectID("")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, primitive.NilObjectID, result)
|
||||
assert.Equal(t, bson.NilObjectID, result)
|
||||
assert.Contains(t, err.Error(), "empty object ID")
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestParseObjectID(t *testing.T) {
|
||||
result, err := parseObjectID("invalid-hex-string")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, primitive.NilObjectID, result)
|
||||
assert.Equal(t, bson.NilObjectID, result)
|
||||
assert.Contains(t, err.Error(), "invalid object ID")
|
||||
})
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestParseObjectID(t *testing.T) {
|
||||
result, err := parseObjectID("abc123")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, primitive.NilObjectID, result)
|
||||
assert.Equal(t, bson.NilObjectID, result)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestValidatePostingLines(t *testing.T) {
|
||||
t.Run("ValidPostingLines", func(t *testing.T) {
|
||||
lines := []*ledgerv1.PostingLine{
|
||||
{
|
||||
LedgerAccountRef: primitive.NewObjectID().Hex(),
|
||||
LedgerAccountRef: bson.NewObjectID().Hex(),
|
||||
Money: &moneyv1.Money{
|
||||
Amount: "10.00",
|
||||
Currency: "USD",
|
||||
@@ -192,7 +192,7 @@ func TestValidatePostingLines(t *testing.T) {
|
||||
t.Run("NilMoney", func(t *testing.T) {
|
||||
lines := []*ledgerv1.PostingLine{
|
||||
{
|
||||
LedgerAccountRef: primitive.NewObjectID().Hex(),
|
||||
LedgerAccountRef: bson.NewObjectID().Hex(),
|
||||
Money: nil,
|
||||
},
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func TestValidatePostingLines(t *testing.T) {
|
||||
t.Run("MainLineType", func(t *testing.T) {
|
||||
lines := []*ledgerv1.PostingLine{
|
||||
{
|
||||
LedgerAccountRef: primitive.NewObjectID().Hex(),
|
||||
LedgerAccountRef: bson.NewObjectID().Hex(),
|
||||
Money: &moneyv1.Money{
|
||||
Amount: "10.00",
|
||||
Currency: "USD",
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// CheckExternalInvariant validates the external_source/external_sink invariant for a currency.
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Service) listAccountsResponder(_ context.Context, req *ledgerv1.ListAcc
|
||||
var filter *storage.AccountsFilter
|
||||
if req.GetOwnerRefFilter() != nil {
|
||||
ownerRefStr := strings.TrimSpace(req.GetOwnerRefFilter().GetValue())
|
||||
var ownerRef primitive.ObjectID
|
||||
var ownerRef bson.ObjectID
|
||||
if ownerRefStr != "" {
|
||||
ownerRef, err = parseObjectID(ownerRefStr)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
me "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -24,8 +24,8 @@ func TestOutboxPublisherDispatchSuccess(t *testing.T) {
|
||||
Payload: []byte(`{"journalEntryRef":"abc123"}`),
|
||||
Attempts: 0,
|
||||
}
|
||||
event.SetID(primitive.NewObjectID())
|
||||
event.OrganizationRef = primitive.NewObjectID()
|
||||
event.SetID(bson.NewObjectID())
|
||||
event.OrganizationRef = bson.NewObjectID()
|
||||
|
||||
store := &recordingOutboxStore{
|
||||
pending: []*model.OutboxEvent{event},
|
||||
@@ -62,8 +62,8 @@ func TestOutboxPublisherDispatchFailureMarksAttempts(t *testing.T) {
|
||||
Payload: []byte(`{"journalEntryRef":"xyz789"}`),
|
||||
Attempts: maxOutboxDeliveryAttempts - 1,
|
||||
}
|
||||
event.SetID(primitive.NewObjectID())
|
||||
event.OrganizationRef = primitive.NewObjectID()
|
||||
event.SetID(bson.NewObjectID())
|
||||
event.OrganizationRef = bson.NewObjectID()
|
||||
|
||||
store := &recordingOutboxStore{
|
||||
pending: []*model.OutboxEvent{event},
|
||||
@@ -89,9 +89,9 @@ type recordingOutboxStore struct {
|
||||
|
||||
pending []*model.OutboxEvent
|
||||
|
||||
markedSent []primitive.ObjectID
|
||||
markedFailed []primitive.ObjectID
|
||||
incremented []primitive.ObjectID
|
||||
markedSent []bson.ObjectID
|
||||
markedFailed []bson.ObjectID
|
||||
incremented []bson.ObjectID
|
||||
}
|
||||
|
||||
func (s *recordingOutboxStore) Create(context.Context, *model.OutboxEvent) error {
|
||||
@@ -106,7 +106,7 @@ func (s *recordingOutboxStore) ListPending(context.Context, int) ([]*model.Outbo
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef primitive.ObjectID, sentAt time.Time) error {
|
||||
func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef bson.ObjectID, sentAt time.Time) error {
|
||||
_ = sentAt
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@@ -114,14 +114,14 @@ func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef primitive.Ob
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *recordingOutboxStore) MarkFailed(_ context.Context, eventRef primitive.ObjectID) error {
|
||||
func (s *recordingOutboxStore) MarkFailed(_ context.Context, eventRef bson.ObjectID) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.markedFailed = append(s.markedFailed, eventRef)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *recordingOutboxStore) IncrementAttempts(_ context.Context, eventRef primitive.ObjectID) error {
|
||||
func (s *recordingOutboxStore) IncrementAttempts(_ context.Context, eventRef bson.ObjectID) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.incremented = append(s.incremented, eventRef)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -89,7 +89,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
eventTime := getEventTime(req.EventTime)
|
||||
creditAmount, _ := parseDecimal(req.Money.Amount)
|
||||
@@ -109,7 +109,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi
|
||||
|
||||
postingLines := make([]*model.PostingLine, 0, 2+len(charges))
|
||||
mainLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: accountRef,
|
||||
Amount: creditAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
@@ -146,7 +146,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi
|
||||
entryTotal = entryTotal.Add(chargeAmount)
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
@@ -170,7 +170,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi
|
||||
contraAmount := entryTotal.Neg()
|
||||
if !contraAmount.IsZero() || len(postingLines) == 1 {
|
||||
contraLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: *contraAccountID,
|
||||
Amount: contraAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
eventTime := getEventTime(req.EventTime)
|
||||
debitAmount, _ := parseDecimal(req.Money.Amount)
|
||||
@@ -106,7 +106,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR
|
||||
|
||||
postingLines := make([]*model.PostingLine, 0, 2+len(charges))
|
||||
mainLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: accountRef,
|
||||
Amount: debitAmount.Neg().String(),
|
||||
Currency: req.Money.Currency,
|
||||
@@ -143,7 +143,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR
|
||||
entryTotal = entryTotal.Add(chargeAmount)
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
@@ -167,7 +167,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR
|
||||
contraAmount := entryTotal.Neg()
|
||||
if !contraAmount.IsZero() || len(postingLines) == 1 {
|
||||
contraLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: *contraAccountID,
|
||||
Amount: contraAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -100,7 +100,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
return nil, merrors.Internal("system account missing identifier")
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{
|
||||
accountRef: account,
|
||||
*systemAccountID: systemAccount,
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
|
||||
postingLines := make([]*model.PostingLine, 0, 2+len(charges))
|
||||
mainLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: accountRef,
|
||||
Amount: creditAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
@@ -160,7 +160,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
entryTotal = entryTotal.Add(chargeAmount)
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
@@ -173,7 +173,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
contraAmount := entryTotal.Neg()
|
||||
if !contraAmount.IsZero() || len(postingLines) == 1 {
|
||||
contraLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: *systemAccountID,
|
||||
Amount: contraAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
@@ -333,7 +333,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
return nil, merrors.Internal("system account missing identifier")
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{
|
||||
accountRef: account,
|
||||
*systemAccountID: systemAccount,
|
||||
}
|
||||
@@ -356,7 +356,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
|
||||
postingLines := make([]*model.PostingLine, 0, 2+len(charges))
|
||||
mainLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: accountRef,
|
||||
Amount: debitAmount.Neg().String(),
|
||||
Currency: req.Money.Currency,
|
||||
@@ -393,7 +393,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
entryTotal = entryTotal.Add(chargeAmount)
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
@@ -406,7 +406,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
contraAmount := entryTotal.Neg()
|
||||
if !contraAmount.IsZero() || len(postingLines) == 1 {
|
||||
contraLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: *systemAccountID,
|
||||
Amount: contraAmount.String(),
|
||||
Currency: req.Money.Currency,
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -115,7 +115,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("to_account: %s", err.Error()))
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{
|
||||
fromAccountRef: fromAccount,
|
||||
toAccountRef: toAccount,
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp
|
||||
|
||||
// Debit from account
|
||||
fromLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: fromAccountRef,
|
||||
Amount: fromAmount.Neg().String(), // negative = debit
|
||||
Currency: req.FromMoney.Currency,
|
||||
@@ -142,7 +142,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp
|
||||
|
||||
// Credit to account
|
||||
toLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: toAccountRef,
|
||||
Amount: toAmount.String(), // positive = credit
|
||||
Currency: req.ToMoney.Currency,
|
||||
@@ -175,7 +175,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp
|
||||
}
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -47,23 +47,23 @@ func validateAccountRole(account *pmodel.LedgerAccount, expected pmodel.AccountR
|
||||
// If accountRefStr is non-empty, it fetches by ID and optionally asserts the role.
|
||||
// If accountRefStr is empty and role is set, it resolves via GetByRole(orgRef, currency, role).
|
||||
// Returns the account and its ObjectID, or an error.
|
||||
func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role pmodel.AccountRole, orgRef primitive.ObjectID, currency, label string) (*pmodel.LedgerAccount, primitive.ObjectID, error) {
|
||||
func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role pmodel.AccountRole, orgRef bson.ObjectID, currency, label string) (*pmodel.LedgerAccount, bson.ObjectID, error) {
|
||||
if accountRefStr != "" {
|
||||
ref, err := parseObjectID(accountRefStr)
|
||||
if err != nil {
|
||||
return nil, primitive.NilObjectID, err
|
||||
return nil, bson.NilObjectID, err
|
||||
}
|
||||
account, err := s.storage.Accounts().Get(ctx, ref)
|
||||
if err != nil {
|
||||
if errors.Is(err, storage.ErrAccountNotFound) {
|
||||
return nil, primitive.NilObjectID, merrors.NoData(label + " not found")
|
||||
return nil, bson.NilObjectID, merrors.NoData(label + " not found")
|
||||
}
|
||||
return nil, primitive.NilObjectID, merrors.Internal("failed to get " + label)
|
||||
return nil, bson.NilObjectID, merrors.Internal("failed to get " + label)
|
||||
}
|
||||
// If role is also specified, assert it matches
|
||||
if role != "" {
|
||||
if err := validateAccountRole(account, role, label); err != nil {
|
||||
return nil, primitive.NilObjectID, err
|
||||
return nil, bson.NilObjectID, err
|
||||
}
|
||||
}
|
||||
return account, ref, nil
|
||||
@@ -71,25 +71,25 @@ func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role
|
||||
|
||||
// No ref provided — resolve by role
|
||||
if role == "" {
|
||||
return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": ledger_account_ref or role is required")
|
||||
return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": ledger_account_ref or role is required")
|
||||
}
|
||||
if orgRef.IsZero() {
|
||||
return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": organization_ref is required for role resolution")
|
||||
return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": organization_ref is required for role resolution")
|
||||
}
|
||||
if currency == "" {
|
||||
return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": currency is required for role resolution")
|
||||
return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": currency is required for role resolution")
|
||||
}
|
||||
account, err := s.storage.Accounts().GetByRole(ctx, orgRef, currency, role)
|
||||
if err != nil {
|
||||
if errors.Is(err, storage.ErrAccountNotFound) {
|
||||
return nil, primitive.NilObjectID, merrors.NoData(fmt.Sprintf("%s: no account found with role %s", label, role))
|
||||
return nil, bson.NilObjectID, merrors.NoData(fmt.Sprintf("%s: no account found with role %s", label, role))
|
||||
}
|
||||
return nil, primitive.NilObjectID, merrors.Internal("failed to resolve " + label + " by role")
|
||||
return nil, bson.NilObjectID, merrors.Internal("failed to resolve " + label + " by role")
|
||||
}
|
||||
return account, *account.GetID(), nil
|
||||
}
|
||||
|
||||
func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef primitive.ObjectID, currency string) error {
|
||||
func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef bson.ObjectID, currency string) error {
|
||||
if account == nil {
|
||||
return merrors.InvalidArgument("account is required")
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef primitive.Objec
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) getAccount(ctx context.Context, cache map[primitive.ObjectID]*pmodel.LedgerAccount, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *Service) getAccount(ctx context.Context, cache map[bson.ObjectID]*pmodel.LedgerAccount, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
if accountRef.IsZero() {
|
||||
return nil, merrors.InvalidArgument("account reference is required")
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (s *Service) getAccount(ctx context.Context, cache map[primitive.ObjectID]*
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef primitive.ObjectID, currency, override string, cache map[primitive.ObjectID]*pmodel.LedgerAccount) (*pmodel.LedgerAccount, error) {
|
||||
func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef bson.ObjectID, currency, override string, cache map[bson.ObjectID]*pmodel.LedgerAccount) (*pmodel.LedgerAccount, error) {
|
||||
if override != "" {
|
||||
overrideRef, err := parseObjectID(override)
|
||||
if err != nil {
|
||||
@@ -172,12 +172,12 @@ func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef primitive
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine, accounts map[primitive.ObjectID]*pmodel.LedgerAccount) error {
|
||||
func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine, accounts map[bson.ObjectID]*pmodel.LedgerAccount) error {
|
||||
if len(lines) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
balanceDeltas := make(map[primitive.ObjectID]decimal.Decimal, len(lines))
|
||||
balanceDeltas := make(map[bson.ObjectID]decimal.Decimal, len(lines))
|
||||
for _, line := range lines {
|
||||
delta, err := parseDecimal(line.Amount)
|
||||
if err != nil {
|
||||
@@ -233,7 +233,7 @@ func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine
|
||||
if account.OrganizationRef != nil {
|
||||
newBalance.OrganizationRef = *account.OrganizationRef
|
||||
} else {
|
||||
newBalance.OrganizationRef = primitive.NilObjectID
|
||||
newBalance.OrganizationRef = bson.NilObjectID
|
||||
}
|
||||
|
||||
if err := balancesStore.Upsert(ctx, newBalance); err != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ func (s *stubRepository) Balances() storage.BalancesStore { return s
|
||||
func (s *stubRepository) Outbox() storage.OutboxStore { return s.outbox }
|
||||
|
||||
type stubAccountsStore struct {
|
||||
getByID map[primitive.ObjectID]*pmodel.LedgerAccount
|
||||
getByID map[bson.ObjectID]*pmodel.LedgerAccount
|
||||
defaultSettlement *pmodel.LedgerAccount
|
||||
getErr error
|
||||
defaultErr error
|
||||
@@ -40,7 +40,7 @@ type stubAccountsStore struct {
|
||||
func (s *stubAccountsStore) Create(context.Context, *pmodel.LedgerAccount) error {
|
||||
return merrors.NotImplemented("create")
|
||||
}
|
||||
func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
if s.getErr != nil {
|
||||
return nil, s.getErr
|
||||
}
|
||||
@@ -49,16 +49,16 @@ func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.Object
|
||||
}
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
func (s *stubAccountsStore) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by code")
|
||||
}
|
||||
func (s *stubAccountsStore) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by role")
|
||||
}
|
||||
func (s *stubAccountsStore) GetSystemAccount(context.Context, pmodel.SystemAccountPurpose, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get system account")
|
||||
}
|
||||
func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
if s.defaultErr != nil {
|
||||
return nil, s.defaultErr
|
||||
}
|
||||
@@ -67,21 +67,21 @@ func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.Obje
|
||||
}
|
||||
return s.defaultSettlement, nil
|
||||
}
|
||||
func (s *stubAccountsStore) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
func (s *stubAccountsStore) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("list")
|
||||
}
|
||||
func (s *stubAccountsStore) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
func (s *stubAccountsStore) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
return merrors.NotImplemented("update status")
|
||||
}
|
||||
|
||||
type stubBalancesStore struct {
|
||||
records map[primitive.ObjectID]*model.AccountBalance
|
||||
records map[bson.ObjectID]*model.AccountBalance
|
||||
upserts []*model.AccountBalance
|
||||
getErr error
|
||||
upErr error
|
||||
}
|
||||
|
||||
func (s *stubBalancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) {
|
||||
func (s *stubBalancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
|
||||
if s.getErr != nil {
|
||||
return nil, s.getErr
|
||||
}
|
||||
@@ -98,13 +98,13 @@ func (s *stubBalancesStore) Upsert(ctx context.Context, balance *model.AccountBa
|
||||
copied := *balance
|
||||
s.upserts = append(s.upserts, &copied)
|
||||
if s.records == nil {
|
||||
s.records = make(map[primitive.ObjectID]*model.AccountBalance)
|
||||
s.records = make(map[bson.ObjectID]*model.AccountBalance)
|
||||
}
|
||||
s.records[balance.AccountRef] = &copied
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubBalancesStore) IncrementBalance(context.Context, primitive.ObjectID, string) error {
|
||||
func (s *stubBalancesStore) IncrementBalance(context.Context, bson.ObjectID, string) error {
|
||||
return merrors.NotImplemented("increment")
|
||||
}
|
||||
|
||||
@@ -126,22 +126,22 @@ func (s *stubOutboxStore) ListPending(context.Context, int) ([]*model.OutboxEven
|
||||
return nil, merrors.NotImplemented("list")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) MarkSent(context.Context, primitive.ObjectID, time.Time) error {
|
||||
func (s *stubOutboxStore) MarkSent(context.Context, bson.ObjectID, time.Time) error {
|
||||
return merrors.NotImplemented("mark sent")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) MarkFailed(context.Context, primitive.ObjectID) error {
|
||||
func (s *stubOutboxStore) MarkFailed(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("mark failed")
|
||||
}
|
||||
|
||||
func (s *stubOutboxStore) IncrementAttempts(context.Context, primitive.ObjectID) error {
|
||||
func (s *stubOutboxStore) IncrementAttempts(context.Context, bson.ObjectID) error {
|
||||
return merrors.NotImplemented("increment attempts")
|
||||
}
|
||||
|
||||
func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
settlementID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
settlementID := bson.NewObjectID()
|
||||
settlement := &pmodel.LedgerAccount{}
|
||||
settlement.SetID(settlementID)
|
||||
settlement.OrganizationRef = &orgRef
|
||||
@@ -151,7 +151,7 @@ func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
accounts := &stubAccountsStore{defaultSettlement: settlement}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount)
|
||||
cache := make(map[bson.ObjectID]*pmodel.LedgerAccount)
|
||||
|
||||
result, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", cache)
|
||||
|
||||
@@ -162,18 +162,18 @@ func TestResolveSettlementAccount_Default(t *testing.T) {
|
||||
|
||||
func TestResolveSettlementAccount_Override(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
overrideID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
overrideID := bson.NewObjectID()
|
||||
override := &pmodel.LedgerAccount{}
|
||||
override.SetID(overrideID)
|
||||
override.OrganizationRef = &orgRef
|
||||
override.Currency = "EUR"
|
||||
override.Status = pmodel.LedgerAccountStatusActive
|
||||
|
||||
accounts := &stubAccountsStore{getByID: map[primitive.ObjectID]*pmodel.LedgerAccount{overrideID: override}}
|
||||
accounts := &stubAccountsStore{getByID: map[bson.ObjectID]*pmodel.LedgerAccount{overrideID: override}}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount)
|
||||
cache := make(map[bson.ObjectID]*pmodel.LedgerAccount)
|
||||
|
||||
result, err := service.resolveSettlementAccount(ctx, orgRef, "EUR", overrideID.Hex(), cache)
|
||||
|
||||
@@ -184,12 +184,12 @@ func TestResolveSettlementAccount_Override(t *testing.T) {
|
||||
|
||||
func TestResolveSettlementAccount_NoDefault(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accounts := &stubAccountsStore{defaultErr: storage.ErrAccountNotFound}
|
||||
repo := &stubRepository{accounts: accounts}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
|
||||
_, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[primitive.ObjectID]*pmodel.LedgerAccount{})
|
||||
_, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[bson.ObjectID]*pmodel.LedgerAccount{})
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -197,8 +197,8 @@ func TestResolveSettlementAccount_NoDefault(t *testing.T) {
|
||||
|
||||
func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"}
|
||||
account.OrganizationRef = &orgRef
|
||||
|
||||
@@ -213,7 +213,7 @@ func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
balances := &stubBalancesStore{}
|
||||
repo := &stubRepository{balances: balances}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
require.NoError(t, service.upsertBalances(ctx, balanceLines, accountCache))
|
||||
require.Len(t, balances.upserts, 1)
|
||||
@@ -224,8 +224,8 @@ func TestUpsertBalances_Succeeds(t *testing.T) {
|
||||
|
||||
func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"}
|
||||
account.OrganizationRef = &orgRef
|
||||
|
||||
@@ -240,7 +240,7 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
balances := &stubBalancesStore{}
|
||||
repo := &stubRepository{balances: balances}
|
||||
service := &Service{logger: zap.NewNop(), storage: repo}
|
||||
accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account}
|
||||
|
||||
err := service.upsertBalances(ctx, balanceLines, accountCache)
|
||||
|
||||
@@ -250,8 +250,8 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) {
|
||||
|
||||
func TestEnqueueOutbox_CreatesEvent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
orgRef := primitive.NewObjectID()
|
||||
entryID := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
entryID := bson.NewObjectID()
|
||||
entry := &model.JournalEntry{
|
||||
IdempotencyKey: "idem",
|
||||
EventTime: time.Now().UTC(),
|
||||
@@ -263,7 +263,7 @@ func TestEnqueueOutbox_CreatesEvent(t *testing.T) {
|
||||
|
||||
lines := []*model.PostingLine{
|
||||
{
|
||||
AccountRef: primitive.NewObjectID(),
|
||||
AccountRef: bson.NewObjectID(),
|
||||
Amount: "100",
|
||||
Currency: "USD",
|
||||
LineType: model.LineTypeMain,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -121,7 +121,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq
|
||||
return nil, merrors.InvalidArgument("cannot transfer to same account")
|
||||
}
|
||||
|
||||
accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{
|
||||
accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{
|
||||
fromAccountRef: fromAccount,
|
||||
toAccountRef: toAccount,
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq
|
||||
|
||||
// Debit from account
|
||||
fromLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: fromAccountRef,
|
||||
Amount: transferAmount.Neg().String(), // negative = debit
|
||||
Currency: req.Money.Currency,
|
||||
@@ -147,7 +147,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq
|
||||
|
||||
// Credit to account
|
||||
toLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: toAccountRef,
|
||||
Amount: transferAmount.String(), // positive = credit
|
||||
Currency: req.Money.Currency,
|
||||
@@ -184,7 +184,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq
|
||||
}
|
||||
|
||||
chargeLine := &model.PostingLine{
|
||||
JournalEntryRef: primitive.NilObjectID,
|
||||
JournalEntryRef: bson.NilObjectID,
|
||||
AccountRef: chargeAccountRef,
|
||||
Amount: chargeAmount.String(),
|
||||
Currency: charge.Money.Currency,
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// EnsureSystemAccounts initializes required system accounts once at startup.
|
||||
@@ -128,7 +128,7 @@ func (s *Service) cacheSystemAccount(purpose pmodel.SystemAccountPurpose, curren
|
||||
}
|
||||
|
||||
func newExternalSystemAccount(purpose pmodel.SystemAccountPurpose, currency string) *pmodel.LedgerAccount {
|
||||
ref := primitive.NewObjectID()
|
||||
ref := bson.NewObjectID()
|
||||
purposeCopy := purpose
|
||||
account := &pmodel.LedgerAccount{
|
||||
AccountCode: generateAccountCode(pmodel.LedgerAccountTypeAsset, currency, ref),
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ type systemAccountsStoreStub struct {
|
||||
|
||||
func (s *systemAccountsStoreStub) Create(_ context.Context, account *pmodel.LedgerAccount) error {
|
||||
if account.GetID() == nil || account.GetID().IsZero() {
|
||||
account.SetID(primitive.NewObjectID())
|
||||
account.SetID(bson.NewObjectID())
|
||||
}
|
||||
s.created = append(s.created, account)
|
||||
if s.existing == nil {
|
||||
@@ -32,15 +32,15 @@ func (s *systemAccountsStoreStub) Create(_ context.Context, account *pmodel.Ledg
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) Get(context.Context, primitive.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
func (s *systemAccountsStoreStub) Get(context.Context, bson.ObjectID) (*pmodel.LedgerAccount, error) {
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *systemAccountsStoreStub) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by code")
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *systemAccountsStoreStub) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get by role")
|
||||
}
|
||||
|
||||
@@ -55,15 +55,15 @@ func (s *systemAccountsStoreStub) GetSystemAccount(_ context.Context, purpose pm
|
||||
return nil, storage.ErrAccountNotFound
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
func (s *systemAccountsStoreStub) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("get default settlement")
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
func (s *systemAccountsStoreStub) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) {
|
||||
return nil, merrors.NotImplemented("list")
|
||||
}
|
||||
|
||||
func (s *systemAccountsStoreStub) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
func (s *systemAccountsStoreStub) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error {
|
||||
return merrors.NotImplemented("update status")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ func isRequiredTopologyRole(role pmodel.AccountRole) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef primitive.ObjectID, currency string) error {
|
||||
func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef bson.ObjectID, currency string) error {
|
||||
if s.storage == nil || s.storage.Accounts() == nil {
|
||||
return errStorageNotInitialized
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef primitive.Obj
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) ensureRoleAccount(ctx context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
func (s *Service) ensureRoleAccount(ctx context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) {
|
||||
if s.storage == nil || s.storage.Accounts() == nil {
|
||||
return nil, errStorageNotInitialized
|
||||
}
|
||||
@@ -104,8 +104,8 @@ func (s *Service) ensureRoleAccount(ctx context.Context, orgRef primitive.Object
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func newSystemAccount(orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount {
|
||||
ref := primitive.NewObjectID()
|
||||
func newSystemAccount(orgRef bson.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount {
|
||||
ref := bson.NewObjectID()
|
||||
account := &pmodel.LedgerAccount{
|
||||
AccountCode: generateAccountCode(pmodel.LedgerAccountTypeAsset, currency, ref),
|
||||
AccountType: pmodel.LedgerAccountTypeAsset,
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// AccountBalance represents the current balance of a ledger account.
|
||||
@@ -14,11 +14,11 @@ type AccountBalance struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
model.OrganizationBoundBase `bson:",inline" json:",inline"`
|
||||
|
||||
AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` // unique per account+currency
|
||||
Balance string `bson:"balance" json:"balance"` // stored as string for exact decimal
|
||||
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
|
||||
Version int64 `bson:"version" json:"version"` // for optimistic locking
|
||||
LastUpdated time.Time `bson:"lastUpdated" json:"lastUpdated"` // timestamp of last balance update
|
||||
AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` // unique per account+currency
|
||||
Balance string `bson:"balance" json:"balance"` // stored as string for exact decimal
|
||||
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
|
||||
Version int64 `bson:"version" json:"version"` // for optimistic locking
|
||||
LastUpdated time.Time `bson:"lastUpdated" json:"lastUpdated"` // timestamp of last balance update
|
||||
}
|
||||
|
||||
// Collection implements storable.Storable.
|
||||
|
||||
@@ -3,7 +3,7 @@ package model
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// PostingLine represents a single debit or credit line in a journal entry.
|
||||
@@ -11,11 +11,11 @@ type PostingLine struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
model.OrganizationBoundBase `bson:",inline" json:",inline"`
|
||||
|
||||
JournalEntryRef primitive.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"`
|
||||
AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"`
|
||||
Amount string `bson:"amount" json:"amount"` // stored as string for exact decimal, positive = credit, negative = debit
|
||||
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
|
||||
LineType LineType `bson:"lineType" json:"lineType"` // main, fee, spread, reversal
|
||||
JournalEntryRef bson.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"`
|
||||
AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"`
|
||||
Amount string `bson:"amount" json:"amount"` // stored as string for exact decimal, positive = credit, negative = debit
|
||||
Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code
|
||||
LineType LineType `bson:"lineType" json:"lineType"` // main, fee, spread, reversal
|
||||
}
|
||||
|
||||
// Collection implements storable.Storable.
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
pkm "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (a *accountsStore) Create(ctx context.Context, account *pkm.LedgerAccount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pkm.LedgerAccount, error) {
|
||||
func (a *accountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pkm.LedgerAccount, error) {
|
||||
if accountRef.IsZero() {
|
||||
a.logger.Warn("Attempt to get account with zero ID")
|
||||
return nil, merrors.InvalidArgument("accountsStore: zero account ID")
|
||||
@@ -134,7 +134,7 @@ func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) {
|
||||
func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef bson.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) {
|
||||
if orgRef.IsZero() {
|
||||
a.logger.Warn("Attempt to get account with zero organization ID")
|
||||
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
|
||||
@@ -167,7 +167,7 @@ func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.O
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) GetByRole(ctx context.Context, orgRef primitive.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) {
|
||||
func (a *accountsStore) GetByRole(ctx context.Context, orgRef bson.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) {
|
||||
if orgRef.IsZero() {
|
||||
a.logger.Warn("Attempt to get account with zero organization ID")
|
||||
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
|
||||
@@ -240,7 +240,7 @@ func (a *accountsStore) GetSystemAccount(ctx context.Context, purpose pkm.System
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pkm.LedgerAccount, error) {
|
||||
func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef bson.ObjectID, currency string) (*pkm.LedgerAccount, error) {
|
||||
if orgRef.IsZero() {
|
||||
a.logger.Warn("Attempt to get default settlement with zero organization ID")
|
||||
return nil, merrors.InvalidArgument("accountsStore: zero organization ID")
|
||||
@@ -275,7 +275,7 @@ func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primiti
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) {
|
||||
func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) {
|
||||
if orgRef.IsZero() {
|
||||
a.logger.Warn("Attempt to list accounts with zero organization reference")
|
||||
return nil, merrors.InvalidArgument("accountsStore: zero organization reference")
|
||||
@@ -316,7 +316,7 @@ func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef primitive.ObjectID, status pkm.LedgerAccountStatus) error {
|
||||
func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef bson.ObjectID, status pkm.LedgerAccountStatus) error {
|
||||
if accountRef.IsZero() {
|
||||
a.logger.Warn("Attempt to update account status with zero reference")
|
||||
return merrors.InvalidArgument("accountsStore: zero account reference")
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
pkm "github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -105,9 +105,9 @@ func TestAccountsStore_Get(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
account := result.(*pkm.LedgerAccount)
|
||||
account.SetID(accountRef)
|
||||
account.AccountCode = "1000"
|
||||
@@ -129,7 +129,7 @@ func TestAccountsStore_Get(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &accountsStore{logger: logger, repo: stub}
|
||||
|
||||
result, err := store.Get(ctx, primitive.NilObjectID)
|
||||
result, err := store.Get(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -137,9 +137,9 @@ func TestAccountsStore_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
return merrors.ErrNoData
|
||||
},
|
||||
}
|
||||
@@ -153,10 +153,10 @@ func TestAccountsStore_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("GetError", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
return expectedErr
|
||||
},
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func TestAccountsStore_Get(t *testing.T) {
|
||||
func TestAccountsStore_GetByAccountCode(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
stub := &repositoryStub{
|
||||
@@ -198,7 +198,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &accountsStore{logger: logger, repo: stub}
|
||||
|
||||
result, err := store.GetByAccountCode(ctx, primitive.NilObjectID, "1000", "USD")
|
||||
result, err := store.GetByAccountCode(ctx, bson.NilObjectID, "1000", "USD")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -246,7 +246,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) {
|
||||
func TestAccountsStore_GetByRole(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
stub := &repositoryStub{
|
||||
@@ -269,7 +269,7 @@ func TestAccountsStore_GetByRole(t *testing.T) {
|
||||
|
||||
t.Run("ZeroOrganizationID", func(t *testing.T) {
|
||||
store := &accountsStore{logger: logger, repo: &repositoryStub{}}
|
||||
result, err := store.GetByRole(ctx, primitive.NilObjectID, "USD", pkm.AccountRoleOperating)
|
||||
result, err := store.GetByRole(ctx, bson.NilObjectID, "USD", pkm.AccountRoleOperating)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -329,13 +329,13 @@ func TestAccountsStore_GetByRole(t *testing.T) {
|
||||
func TestAccountsStore_GetDefaultSettlement(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
stub := &repositoryStub{
|
||||
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
|
||||
account := result.(*pkm.LedgerAccount)
|
||||
account.SetID(primitive.NewObjectID())
|
||||
account.SetID(bson.NewObjectID())
|
||||
account.Currency = "USD"
|
||||
account.Role = pkm.AccountRoleSettlement
|
||||
return nil
|
||||
@@ -353,7 +353,7 @@ func TestAccountsStore_GetDefaultSettlement(t *testing.T) {
|
||||
|
||||
t.Run("ZeroOrganizationID", func(t *testing.T) {
|
||||
store := &accountsStore{logger: logger, repo: &repositoryStub{}}
|
||||
result, err := store.GetDefaultSettlement(ctx, primitive.NilObjectID, "USD")
|
||||
result, err := store.GetDefaultSettlement(ctx, bson.NilObjectID, "USD")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -481,7 +481,7 @@ func TestAccountsStore_GetSystemAccount(t *testing.T) {
|
||||
func TestAccountsStore_ListByOrganization(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var calledWithQuery bool
|
||||
@@ -506,7 +506,7 @@ func TestAccountsStore_ListByOrganization(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &accountsStore{logger: logger, repo: stub}
|
||||
|
||||
results, err := store.ListByOrganization(ctx, primitive.NilObjectID, nil, 10, 0)
|
||||
results, err := store.ListByOrganization(ctx, bson.NilObjectID, nil, 10, 0)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, results)
|
||||
@@ -547,13 +547,13 @@ func TestAccountsStore_ListByOrganization(t *testing.T) {
|
||||
func TestAccountsStore_UpdateStatus(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var patchedID primitive.ObjectID
|
||||
var patchedID bson.ObjectID
|
||||
var patchedStatus pkm.LedgerAccountStatus
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
patchedID = id
|
||||
// In real test, we'd inspect patch builder but this is sufficient for stub
|
||||
patchedStatus = pkm.LedgerAccountStatusFrozen
|
||||
@@ -573,7 +573,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &accountsStore{logger: logger, repo: stub}
|
||||
|
||||
err := store.UpdateStatus(ctx, primitive.NilObjectID, pkm.LedgerAccountStatusFrozen)
|
||||
err := store.UpdateStatus(ctx, bson.NilObjectID, pkm.LedgerAccountStatusFrozen)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -582,7 +582,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) {
|
||||
t.Run("PatchError", func(t *testing.T) {
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
return expectedErr
|
||||
},
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -45,7 +45,7 @@ func NewBalances(logger mlogger.Logger, db *mongo.Database) (storage.BalancesSto
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *balancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) {
|
||||
func (b *balancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) {
|
||||
if accountRef.IsZero() {
|
||||
b.logger.Warn("attempt to get balance with zero account ID")
|
||||
return nil, merrors.InvalidArgument("balancesStore: zero account ID")
|
||||
@@ -98,7 +98,7 @@ func (b *balancesStore) Upsert(ctx context.Context, balance *model.AccountBalanc
|
||||
return b.repo.Update(ctx, balance)
|
||||
}
|
||||
|
||||
func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef primitive.ObjectID, amount string) error {
|
||||
func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef bson.ObjectID, amount string) error {
|
||||
if accountRef.IsZero() {
|
||||
b.logger.Warn("attempt to increment balance with zero account ID")
|
||||
return merrors.InvalidArgument("balancesStore: zero account ID")
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestBalancesStore_Get(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
|
||||
balance := result.(*model.AccountBalance)
|
||||
@@ -46,7 +46,7 @@ func TestBalancesStore_Get(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &balancesStore{logger: logger, repo: stub}
|
||||
|
||||
result, err := store.Get(ctx, primitive.NilObjectID)
|
||||
result, err := store.Get(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -54,7 +54,7 @@ func TestBalancesStore_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
|
||||
return merrors.ErrNoData
|
||||
@@ -70,7 +70,7 @@ func TestBalancesStore_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("FindError", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error {
|
||||
@@ -92,7 +92,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
t.Run("Insert_NewBalance", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
var insertedBalance *model.AccountBalance
|
||||
|
||||
stub := &repositoryStub{
|
||||
@@ -120,8 +120,8 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Update_ExistingBalance", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
existingID := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
existingID := bson.NewObjectID()
|
||||
var updatedBalance *model.AccountBalance
|
||||
|
||||
stub := &repositoryStub{
|
||||
@@ -170,7 +170,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
store := &balancesStore{logger: logger, repo: stub}
|
||||
|
||||
balance := &model.AccountBalance{
|
||||
AccountRef: primitive.NilObjectID,
|
||||
AccountRef: bson.NilObjectID,
|
||||
Balance: "100.00",
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("FindError", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
expectedErr := errors.New("database error")
|
||||
|
||||
stub := &repositoryStub{
|
||||
@@ -203,7 +203,7 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InsertError", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
expectedErr := errors.New("insert error")
|
||||
|
||||
stub := &repositoryStub{
|
||||
@@ -228,8 +228,8 @@ func TestBalancesStore_Upsert(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("UpdateError", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
existingID := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
existingID := bson.NewObjectID()
|
||||
expectedErr := errors.New("update error")
|
||||
|
||||
stub := &repositoryStub{
|
||||
@@ -263,7 +263,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
t.Run("NotImplemented", func(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{}
|
||||
store := &balancesStore{logger: logger, repo: stub}
|
||||
|
||||
@@ -277,7 +277,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &balancesStore{logger: logger, repo: stub}
|
||||
|
||||
err := store.IncrementBalance(ctx, primitive.NilObjectID, "100.00")
|
||||
err := store.IncrementBalance(ctx, bson.NilObjectID, "100.00")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ func (j *journalEntriesStore) Create(ctx context.Context, entry *model.JournalEn
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.ObjectID) (*model.JournalEntry, error) {
|
||||
func (j *journalEntriesStore) Get(ctx context.Context, entryRef bson.ObjectID) (*model.JournalEntry, error) {
|
||||
if entryRef.IsZero() {
|
||||
j.logger.Warn("attempt to get journal entry with zero ID")
|
||||
return nil, merrors.InvalidArgument("journalEntriesStore: zero entry ID")
|
||||
@@ -99,7 +99,7 @@ func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.Object
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.JournalEntry, error) {
|
||||
func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.JournalEntry, error) {
|
||||
if orgRef.IsZero() {
|
||||
j.logger.Warn("attempt to get journal entry with zero organization ID")
|
||||
return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID")
|
||||
@@ -128,7 +128,7 @@ func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef pr
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) {
|
||||
func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) {
|
||||
if orgRef.IsZero() {
|
||||
j.logger.Warn("attempt to list journal entries with zero organization ID")
|
||||
return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID")
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -107,9 +107,9 @@ func TestJournalEntriesStore_Get(t *testing.T) {
|
||||
logger := zap.NewNop()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
entryRef := primitive.NewObjectID()
|
||||
entryRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
entry := result.(*model.JournalEntry)
|
||||
entry.SetID(entryRef)
|
||||
entry.IdempotencyKey = "test-key-123"
|
||||
@@ -131,7 +131,7 @@ func TestJournalEntriesStore_Get(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &journalEntriesStore{logger: logger, repo: stub}
|
||||
|
||||
result, err := store.Get(ctx, primitive.NilObjectID)
|
||||
result, err := store.Get(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -139,9 +139,9 @@ func TestJournalEntriesStore_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
entryRef := primitive.NewObjectID()
|
||||
entryRef := bson.NewObjectID()
|
||||
stub := &repositoryStub{
|
||||
GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
return merrors.ErrNoData
|
||||
},
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func TestJournalEntriesStore_Get(t *testing.T) {
|
||||
func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
stub := &repositoryStub{
|
||||
@@ -183,7 +183,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &journalEntriesStore{logger: logger, repo: stub}
|
||||
|
||||
result, err := store.GetByIdempotencyKey(ctx, primitive.NilObjectID, "test-key")
|
||||
result, err := store.GetByIdempotencyKey(ctx, bson.NilObjectID, "test-key")
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, result)
|
||||
@@ -220,7 +220,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) {
|
||||
func TestJournalEntriesStore_ListByOrganization(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
orgRef := primitive.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
called := false
|
||||
@@ -243,7 +243,7 @@ func TestJournalEntriesStore_ListByOrganization(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &journalEntriesStore{logger: logger, repo: stub}
|
||||
|
||||
results, err := store.ListByOrganization(ctx, primitive.NilObjectID, 10, 0)
|
||||
results, err := store.ListByOrganization(ctx, bson.NilObjectID, 10, 0)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, results)
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -101,7 +101,7 @@ func (o *outboxStore) ListPending(ctx context.Context, limit int) ([]*model.Outb
|
||||
return events, nil
|
||||
}
|
||||
|
||||
func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID, sentAt time.Time) error {
|
||||
func (o *outboxStore) MarkSent(ctx context.Context, eventRef bson.ObjectID, sentAt time.Time) error {
|
||||
if eventRef.IsZero() {
|
||||
o.logger.Warn("attempt to mark sent with zero event ID")
|
||||
return merrors.InvalidArgument("outboxStore: zero event ID")
|
||||
@@ -120,7 +120,7 @@ func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectID) error {
|
||||
func (o *outboxStore) MarkFailed(ctx context.Context, eventRef bson.ObjectID) error {
|
||||
if eventRef.IsZero() {
|
||||
o.logger.Warn("attempt to mark failed with zero event ID")
|
||||
return merrors.InvalidArgument("outboxStore: zero event ID")
|
||||
@@ -137,7 +137,7 @@ func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectI
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef primitive.ObjectID) error {
|
||||
func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef bson.ObjectID) error {
|
||||
if eventRef.IsZero() {
|
||||
o.logger.Warn("attempt to increment attempts with zero event ID")
|
||||
return merrors.InvalidArgument("outboxStore: zero event ID")
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -176,13 +176,13 @@ func TestOutboxStore_ListPending(t *testing.T) {
|
||||
func TestOutboxStore_MarkSent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
eventRef := primitive.NewObjectID()
|
||||
eventRef := bson.NewObjectID()
|
||||
sentTime := time.Now()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var patchedID primitive.ObjectID
|
||||
var patchedID bson.ObjectID
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
patchedID = id
|
||||
return nil
|
||||
},
|
||||
@@ -199,7 +199,7 @@ func TestOutboxStore_MarkSent(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &outboxStore{logger: logger, repo: stub}
|
||||
|
||||
err := store.MarkSent(ctx, primitive.NilObjectID, sentTime)
|
||||
err := store.MarkSent(ctx, bson.NilObjectID, sentTime)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -208,7 +208,7 @@ func TestOutboxStore_MarkSent(t *testing.T) {
|
||||
t.Run("PatchError", func(t *testing.T) {
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
return expectedErr
|
||||
},
|
||||
}
|
||||
@@ -224,12 +224,12 @@ func TestOutboxStore_MarkSent(t *testing.T) {
|
||||
func TestOutboxStore_MarkFailed(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
eventRef := primitive.NewObjectID()
|
||||
eventRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var patchedID primitive.ObjectID
|
||||
var patchedID bson.ObjectID
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
patchedID = id
|
||||
return nil
|
||||
},
|
||||
@@ -246,7 +246,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &outboxStore{logger: logger, repo: stub}
|
||||
|
||||
err := store.MarkFailed(ctx, primitive.NilObjectID)
|
||||
err := store.MarkFailed(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -255,7 +255,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
|
||||
t.Run("PatchError", func(t *testing.T) {
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
return expectedErr
|
||||
},
|
||||
}
|
||||
@@ -271,12 +271,12 @@ func TestOutboxStore_MarkFailed(t *testing.T) {
|
||||
func TestOutboxStore_IncrementAttempts(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
eventRef := primitive.NewObjectID()
|
||||
eventRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var patchedID primitive.ObjectID
|
||||
var patchedID bson.ObjectID
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
patchedID = id
|
||||
return nil
|
||||
},
|
||||
@@ -293,7 +293,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &outboxStore{logger: logger, repo: stub}
|
||||
|
||||
err := store.IncrementAttempts(ctx, primitive.NilObjectID)
|
||||
err := store.IncrementAttempts(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrInvalidArg))
|
||||
@@ -302,7 +302,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
|
||||
t.Run("PatchError", func(t *testing.T) {
|
||||
expectedErr := errors.New("database error")
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
return expectedErr
|
||||
},
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) {
|
||||
t.Run("MultipleIncrements", func(t *testing.T) {
|
||||
var callCount int
|
||||
stub := &repositoryStub{
|
||||
PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error {
|
||||
PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error {
|
||||
callCount++
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -80,7 +80,7 @@ func (p *postingLinesStore) CreateMany(ctx context.Context, lines []*model.Posti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef primitive.ObjectID) ([]*model.PostingLine, error) {
|
||||
func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef bson.ObjectID) ([]*model.PostingLine, error) {
|
||||
if entryRef.IsZero() {
|
||||
p.logger.Warn("attempt to list posting lines with zero entry ID")
|
||||
return nil, merrors.InvalidArgument("postingLinesStore: zero entry ID")
|
||||
@@ -106,7 +106,7 @@ func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef pri
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef primitive.ObjectID, limit int, offset int) ([]*model.PostingLine, error) {
|
||||
func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef bson.ObjectID, limit int, offset int) ([]*model.PostingLine, error) {
|
||||
if accountRef.IsZero() {
|
||||
p.logger.Warn("attempt to list posting lines with zero account ID")
|
||||
return nil, merrors.InvalidArgument("postingLinesStore: zero account ID")
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/ledger/storage/model"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
rd "github.com/tech/sendico/pkg/db/repository/decoder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -32,14 +32,14 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
|
||||
store := &postingLinesStore{logger: logger, repo: stub}
|
||||
lines := []*model.PostingLine{
|
||||
{
|
||||
JournalEntryRef: primitive.NewObjectID(),
|
||||
AccountRef: primitive.NewObjectID(),
|
||||
JournalEntryRef: bson.NewObjectID(),
|
||||
AccountRef: bson.NewObjectID(),
|
||||
LineType: model.LineTypeMain,
|
||||
Amount: "100.00",
|
||||
},
|
||||
{
|
||||
JournalEntryRef: primitive.NewObjectID(),
|
||||
AccountRef: primitive.NewObjectID(),
|
||||
JournalEntryRef: bson.NewObjectID(),
|
||||
AccountRef: bson.NewObjectID(),
|
||||
LineType: model.LineTypeMain,
|
||||
Amount: "100.00",
|
||||
},
|
||||
@@ -104,9 +104,9 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
|
||||
}
|
||||
|
||||
store := &postingLinesStore{logger: logger, repo: stub}
|
||||
entryRef := primitive.NewObjectID()
|
||||
cashAccount := primitive.NewObjectID()
|
||||
revenueAccount := primitive.NewObjectID()
|
||||
entryRef := bson.NewObjectID()
|
||||
cashAccount := bson.NewObjectID()
|
||||
revenueAccount := bson.NewObjectID()
|
||||
|
||||
lines := []*model.PostingLine{
|
||||
{
|
||||
@@ -133,7 +133,7 @@ func TestPostingLinesStore_CreateMany(t *testing.T) {
|
||||
func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
entryRef := primitive.NewObjectID()
|
||||
entryRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
called := false
|
||||
@@ -156,7 +156,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &postingLinesStore{logger: logger, repo: stub}
|
||||
|
||||
results, err := store.ListByJournalEntry(ctx, primitive.NilObjectID)
|
||||
results, err := store.ListByJournalEntry(ctx, bson.NilObjectID)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, results)
|
||||
@@ -197,7 +197,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) {
|
||||
func TestPostingLinesStore_ListByAccount(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logger := zap.NewNop()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
called := false
|
||||
@@ -220,7 +220,7 @@ func TestPostingLinesStore_ListByAccount(t *testing.T) {
|
||||
stub := &repositoryStub{}
|
||||
store := &postingLinesStore{logger: logger, repo: stub}
|
||||
|
||||
results, err := store.ListByAccount(ctx, primitive.NilObjectID, 10, 0)
|
||||
results, err := store.ListByAccount(ctx, bson.NilObjectID, 10, 0)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, results)
|
||||
|
||||
@@ -9,23 +9,23 @@ import (
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// repositoryStub provides a stub implementation of repository.Repository for testing
|
||||
type repositoryStub struct {
|
||||
AggregateFunc func(ctx context.Context, pipeline builder.Pipeline, decoder rd.DecodingFunc) error
|
||||
GetFunc func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error
|
||||
GetFunc func(ctx context.Context, id bson.ObjectID, result storable.Storable) error
|
||||
InsertFunc func(ctx context.Context, object storable.Storable, filter builder.Query) error
|
||||
InsertManyFunc func(ctx context.Context, objects []storable.Storable) error
|
||||
UpdateFunc func(ctx context.Context, object storable.Storable) error
|
||||
DeleteFunc func(ctx context.Context, id primitive.ObjectID) error
|
||||
DeleteFunc func(ctx context.Context, id bson.ObjectID) error
|
||||
FindOneByFilterFunc func(ctx context.Context, filter builder.Query, result storable.Storable) error
|
||||
FindManyByFilterFunc func(ctx context.Context, filter builder.Query, decoder rd.DecodingFunc) error
|
||||
PatchFunc func(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error
|
||||
PatchFunc func(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error
|
||||
PatchManyFunc func(ctx context.Context, filter repository.FilterQuery, patch repository.PatchDoc) (int, error)
|
||||
DeleteManyFunc func(ctx context.Context, query builder.Query) error
|
||||
ListIDsFunc func(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error)
|
||||
ListIDsFunc func(ctx context.Context, query builder.Query) ([]bson.ObjectID, error)
|
||||
CreateIndexFunc func(def *ri.Definition) error
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func (r *repositoryStub) Aggregate(ctx context.Context, pipeline builder.Pipelin
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repositoryStub) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
func (r *repositoryStub) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
if r.GetFunc != nil {
|
||||
return r.GetFunc(ctx, id, result)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (r *repositoryStub) Update(ctx context.Context, object storable.Storable) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repositoryStub) Delete(ctx context.Context, id primitive.ObjectID) error {
|
||||
func (r *repositoryStub) Delete(ctx context.Context, id bson.ObjectID) error {
|
||||
if r.DeleteFunc != nil {
|
||||
return r.DeleteFunc(ctx, id)
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (r *repositoryStub) FindManyByFilter(ctx context.Context, filter builder.Qu
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repositoryStub) Patch(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error {
|
||||
func (r *repositoryStub) Patch(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error {
|
||||
if r.PatchFunc != nil {
|
||||
return r.PatchFunc(ctx, id, patch)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (r *repositoryStub) DeleteMany(ctx context.Context, query builder.Query) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) {
|
||||
func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) {
|
||||
if r.ListIDsFunc != nil {
|
||||
return r.ListIDsFunc(ctx, query)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type mongoTransactionFactory struct {
|
||||
@@ -26,7 +26,7 @@ func (t *mongoTransaction) Execute(ctx context.Context, cb transaction.Callback)
|
||||
}
|
||||
defer session.EndSession(ctx)
|
||||
|
||||
run := func(sessCtx mongo.SessionContext) (any, error) {
|
||||
run := func(sessCtx context.Context) (any, error) {
|
||||
return cb(sessCtx)
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user