fixed upsert
This commit is contained in:
@@ -11,10 +11,12 @@ import (
|
|||||||
"github.com/tech/sendico/gateway/mntx/storage"
|
"github.com/tech/sendico/gateway/mntx/storage"
|
||||||
"github.com/tech/sendico/gateway/mntx/storage/model"
|
"github.com/tech/sendico/gateway/mntx/storage/model"
|
||||||
clockpkg "github.com/tech/sendico/pkg/clock"
|
clockpkg "github.com/tech/sendico/pkg/clock"
|
||||||
|
"github.com/tech/sendico/pkg/db/storable"
|
||||||
"github.com/tech/sendico/pkg/merrors"
|
"github.com/tech/sendico/pkg/merrors"
|
||||||
msg "github.com/tech/sendico/pkg/messaging"
|
msg "github.com/tech/sendico/pkg/messaging"
|
||||||
"github.com/tech/sendico/pkg/mlogger"
|
"github.com/tech/sendico/pkg/mlogger"
|
||||||
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
|
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
|
||||||
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,6 +89,9 @@ func (p *cardPayoutProcessor) Submit(ctx context.Context, req *mntxv1.CardPayout
|
|||||||
now := p.clock.Now()
|
now := p.clock.Now()
|
||||||
|
|
||||||
state := &model.CardPayout{
|
state := &model.CardPayout{
|
||||||
|
Base: storable.Base{
|
||||||
|
ID: bson.NilObjectID,
|
||||||
|
},
|
||||||
PayoutID: strings.TrimSpace(req.GetPayoutId()),
|
PayoutID: strings.TrimSpace(req.GetPayoutId()),
|
||||||
OperationRef: strings.TrimSpace(req.GetOperationRef()),
|
OperationRef: strings.TrimSpace(req.GetOperationRef()),
|
||||||
IdempotencyKey: strings.TrimSpace(req.GetIdempotencyKey()),
|
IdempotencyKey: strings.TrimSpace(req.GetIdempotencyKey()),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||||
"github.com/tech/sendico/pkg/merrors"
|
"github.com/tech/sendico/pkg/merrors"
|
||||||
"github.com/tech/sendico/pkg/mlogger"
|
"github.com/tech/sendico/pkg/mlogger"
|
||||||
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@@ -81,7 +82,11 @@ func (p *Payouts) Upsert(ctx context.Context, record *model.CardPayout) error {
|
|||||||
return merrors.InvalidArgument("operation ref is required", "operation_ref")
|
return merrors.InvalidArgument("operation ref is required", "operation_ref")
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.repository.Insert(ctx, record, repository.Filter(payoutIdemField, record.IdempotencyKey))
|
if record.ID == bson.NilObjectID {
|
||||||
|
return p.repository.Insert(ctx, record, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.repository.Update(ctx, record)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ storage.PayoutsStore = (*Payouts)(nil)
|
var _ storage.PayoutsStore = (*Payouts)(nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user