fixed doc env vars + mongo v2 migration
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/template"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// DB is the interface which must be implemented by all db drivers
|
||||
@@ -13,5 +13,5 @@ type DB interface {
|
||||
template.DB[*model.Account]
|
||||
GetByEmail(ctx context.Context, email string) (*model.Account, error)
|
||||
GetByToken(ctx context.Context, email string) (*model.Account, error)
|
||||
GetAccountsByRefs(ctx context.Context, orgRef primitive.ObjectID, refs []primitive.ObjectID) ([]model.Account, error)
|
||||
GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error)
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/template"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
template.DB[*model.ConfirmationCode]
|
||||
|
||||
FindActive(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error)
|
||||
DeleteTuple(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget) error
|
||||
FindActive(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error)
|
||||
DeleteTuple(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget) error
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
mongoimpl "github.com/tech/sendico/pkg/db/internal/mongo"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
mongoDriver "go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
|
||||
)
|
||||
|
||||
// Connection represents a low-level database connection lifecycle.
|
||||
@@ -18,15 +18,15 @@ type Connection interface {
|
||||
|
||||
// MongoConnection provides direct access to the underlying mongo client.
|
||||
type MongoConnection struct {
|
||||
client *mongoDriver.Client
|
||||
client *mongo.Client
|
||||
database string
|
||||
}
|
||||
|
||||
func (c *MongoConnection) Client() *mongoDriver.Client {
|
||||
func (c *MongoConnection) Client() *mongo.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func (c *MongoConnection) Database() *mongoDriver.Database {
|
||||
func (c *MongoConnection) Database() *mongo.Database {
|
||||
return c.client.Database(c.database)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error
|
||||
Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *AccountDB) GetAccountsByRefs(ctx context.Context, orgRef primitive.ObjectID, refs []primitive.ObjectID) ([]model.Account, error) {
|
||||
func (db *AccountDB) GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error) {
|
||||
filter := repository.Query().Comparison(repository.IDField(), builder.In, refs)
|
||||
return mutil.GetObjects[model.Account](ctx, db.Logger, filter, nil, db.Repository)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewArchivableDB[T storable.Storable](
|
||||
}
|
||||
|
||||
// SetArchived sets the archived status of an entity
|
||||
func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef primitive.ObjectID, archived bool) error {
|
||||
func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef bson.ObjectID, archived bool) error {
|
||||
// Get current object to check current archived status
|
||||
obj := db.createEmpty()
|
||||
if err := db.repo.Get(ctx, objectRef, obj); err != nil {
|
||||
@@ -74,7 +74,7 @@ func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef primitive.
|
||||
}
|
||||
|
||||
// IsArchived checks if an entity is archived
|
||||
func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef primitive.ObjectID) (bool, error) {
|
||||
func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef bson.ObjectID) (bool, error) {
|
||||
obj := db.createEmpty()
|
||||
|
||||
if err := db.repo.Get(ctx, objectRef, obj); err != nil {
|
||||
@@ -89,11 +89,11 @@ func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef primitive.O
|
||||
}
|
||||
|
||||
// Archive archives an entity (sets archived to true)
|
||||
func (db *ArchivableDB[T]) Archive(ctx context.Context, objectRef primitive.ObjectID) error {
|
||||
func (db *ArchivableDB[T]) Archive(ctx context.Context, objectRef bson.ObjectID) error {
|
||||
return db.SetArchived(ctx, objectRef, true)
|
||||
}
|
||||
|
||||
// Unarchive unarchives an entity (sets archived to false)
|
||||
func (db *ArchivableDB[T]) Unarchive(ctx context.Context, objectRef primitive.ObjectID) error {
|
||||
func (db *ArchivableDB[T]) Unarchive(ctx context.Context, objectRef bson.ObjectID) error {
|
||||
return db.SetArchived(ctx, objectRef, false)
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *ConfirmationDB) DeleteTuple(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget) error {
|
||||
func (db *ConfirmationDB) DeleteTuple(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget) error {
|
||||
query := repository.Query().
|
||||
Filter(repository.Field(fieldAccountRef), accountRef).
|
||||
Filter(repository.Field(fieldDestination), destination).
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *ConfirmationDB) FindActive(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) {
|
||||
func (db *ConfirmationDB) FindActive(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) {
|
||||
var res model.ConfirmationCode
|
||||
query := repository.Query().
|
||||
Filter(repository.Field(fieldAccountRef), accountRef).
|
||||
|
||||
@@ -36,8 +36,8 @@ import (
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/config"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -133,7 +133,7 @@ func decodeConfig(logger mlogger.Logger, settings model.SettingsT) (*Config, *DB
|
||||
func dialMongo(logger mlogger.Logger, dbSettings *DBSettings) (*mongo.Client, error) {
|
||||
opts := buildOptions(dbSettings)
|
||||
|
||||
client, err := mongo.Connect(context.Background(), opts)
|
||||
client, err := mongo.Connect(opts)
|
||||
if err != nil {
|
||||
logger.Error("Unable to connect to database", zap.Error(err))
|
||||
return nil, err
|
||||
|
||||
@@ -160,7 +160,7 @@ type IndexableDB[T storable.Storable] struct {
|
||||
}
|
||||
|
||||
// Single filter parameter - clean and simple
|
||||
func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error
|
||||
func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error
|
||||
```
|
||||
|
||||
## Benefits
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewIndexableDB[T storable.Storable](
|
||||
}
|
||||
|
||||
// Reorder implements the db.IndexableDB interface with single filter parameter
|
||||
func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error {
|
||||
func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error {
|
||||
// Get current object to find its index
|
||||
obj := db.createEmpty()
|
||||
err := db.repo.Get(ctx, objectRef, obj)
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *InvitationDB) Accept(ctx context.Context, invitationRef primitive.ObjectID) error {
|
||||
func (db *InvitationDB) Accept(ctx context.Context, invitationRef bson.ObjectID) error {
|
||||
return db.updateStatus(ctx, invitationRef, model.InvitationAccepted)
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"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"
|
||||
)
|
||||
|
||||
// SetArchived sets the archived status of an invitation
|
||||
// Invitation supports archiving through PermissionBound embedding ArchivableBase
|
||||
func (db *InvitationDB) SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef primitive.ObjectID, archived, cascade bool) error {
|
||||
func (db *InvitationDB) SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef bson.ObjectID, archived, cascade bool) error {
|
||||
db.DBImp.Logger.Debug("Setting invitation archived status", mzap.ObjRef("invitation_ref", invitationRef), zap.Bool("archived", archived), zap.Bool("cascade", cascade))
|
||||
res, err := db.Enforcer.Enforce(ctx, db.PermissionRef, accountRef, organizationRef, invitationRef, model.ActionUpdate)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// DeleteCascade deletes an invitation
|
||||
// Invitations don't have cascade dependencies, so this is a simple deletion
|
||||
func (db *InvitationDB) DeleteCascade(ctx context.Context, accountRef, invitationRef primitive.ObjectID) error {
|
||||
func (db *InvitationDB) DeleteCascade(ctx context.Context, accountRef, invitationRef bson.ObjectID) error {
|
||||
db.DBImp.Logger.Debug("Starting invitation cascade deletion", mzap.ObjRef("invitation_ref", invitationRef))
|
||||
|
||||
// Delete the invitation itself (no dependencies to cascade delete)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *InvitationDB) Decline(ctx context.Context, invitationRef primitive.ObjectID) error {
|
||||
func (db *InvitationDB) Decline(ctx context.Context, invitationRef bson.ObjectID) error {
|
||||
return db.updateStatus(ctx, invitationRef, model.InvitationDeclined)
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func (db *InvitationDB) GetPublic(ctx context.Context, invitationRef primitive.ObjectID) (*model.PublicInvitation, error) {
|
||||
func (db *InvitationDB) GetPublic(ctx context.Context, invitationRef bson.ObjectID) (*model.PublicInvitation, error) {
|
||||
roleField := repository.Field("role")
|
||||
orgField := repository.Field("organization")
|
||||
accField := repository.Field("account")
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mauth "github.com/tech/sendico/pkg/mutil/db/auth"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *InvitationDB) List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) {
|
||||
func (db *InvitationDB) List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) {
|
||||
res, err := mauth.GetProtectedObjects[model.Invitation](
|
||||
ctx,
|
||||
db.DBImp.Logger,
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"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"
|
||||
)
|
||||
|
||||
func (db *InvitationDB) updateStatus(ctx context.Context, invitationRef primitive.ObjectID, newStatus model.InvitationStatus) error {
|
||||
func (db *InvitationDB) updateStatus(ctx context.Context, invitationRef bson.ObjectID, newStatus model.InvitationStatus) error {
|
||||
// db.DBImp.Up
|
||||
var inv model.Invitation
|
||||
if err := db.DBImp.FindOne(ctx, repository.IDFilter(invitationRef), &inv); err != nil {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
func buildOptions(s *DBSettings) *options.ClientOptions {
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// SetArchived sets the archived status of an organization and optionally cascades to projects, tasks, comments, and reactions
|
||||
func (db *OrganizationDB) SetArchived(ctx context.Context, accountRef, organizationRef primitive.ObjectID, archived, cascade bool) error {
|
||||
func (db *OrganizationDB) SetArchived(ctx context.Context, accountRef, organizationRef bson.ObjectID, archived, cascade bool) error {
|
||||
db.DBImp.Logger.Debug("Setting organization archived status", mzap.ObjRef("organization_ref", organizationRef), zap.Bool("archived", archived), zap.Bool("cascade", cascade))
|
||||
|
||||
// Get the organization first
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// DeleteCascade deletes an organization and all its related data (projects, tasks, comments, reactions, statuses)
|
||||
func (db *OrganizationDB) DeleteCascade(ctx context.Context, organizationRef primitive.ObjectID) error {
|
||||
func (db *OrganizationDB) DeleteCascade(ctx context.Context, organizationRef bson.ObjectID) error {
|
||||
db.DBImp.Logger.Debug("Starting organization deletion with projects", mzap.ObjRef("organization_ref", organizationRef))
|
||||
|
||||
// Delete the organization itself
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *OrganizationDB) Create(ctx context.Context, _, _ primitive.ObjectID, org *model.Organization) error {
|
||||
func (db *OrganizationDB) Create(ctx context.Context, _, _ bson.ObjectID, org *model.Organization) error {
|
||||
if org == nil {
|
||||
return merrors.InvalidArgument("Organization object is nil", "organization")
|
||||
}
|
||||
org.SetID(primitive.NewObjectID())
|
||||
org.SetID(bson.NewObjectID())
|
||||
// Organizaiton reference must be set to the same value as own organization reference
|
||||
org.SetOrganizationRef(*org.GetID())
|
||||
return db.DBImp.Create(ctx, org)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type OrganizationDB struct {
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *OrganizationDB) GetByRef(ctx context.Context, organizationRef primitive.ObjectID, org *model.Organization) error {
|
||||
func (db *OrganizationDB) GetByRef(ctx context.Context, organizationRef bson.ObjectID, org *model.Organization) error {
|
||||
return db.Unprotected().Get(ctx, organizationRef, org)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *OrganizationDB) List(ctx context.Context, accountRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) {
|
||||
func (db *OrganizationDB) List(ctx context.Context, accountRef bson.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) {
|
||||
filter := repository.Query().Comparison(repository.Field("members"), builder.Eq, accountRef)
|
||||
return mutil.GetObjects[model.Organization](ctx, db.DBImp.Logger, filter, cursor, db.DBImp.Repository)
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *OrganizationDB) ListOwned(ctx context.Context, accountRef primitive.ObjectID) ([]model.Organization, error) {
|
||||
func (db *OrganizationDB) ListOwned(ctx context.Context, accountRef bson.ObjectID) ([]model.Organization, error) {
|
||||
return mutil.GetObjects[model.Organization](ctx, db.DBImp.Logger, repository.Filter("ownerRef", accountRef), nil, db.DBImp.Repository)
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"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"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgDB := newTestOrganizationDB(t)
|
||||
|
||||
org := &model.Organization{
|
||||
@@ -32,7 +32,7 @@ func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) {
|
||||
TimeZone: "UTC",
|
||||
},
|
||||
}
|
||||
org.SetID(primitive.NewObjectID())
|
||||
org.SetID(bson.NewObjectID())
|
||||
|
||||
require.NoError(t, orgDB.Create(ctx, accountRef, *org.GetID(), org))
|
||||
|
||||
@@ -51,10 +51,10 @@ func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) {
|
||||
|
||||
func TestOrganizationDB_SetArchived_UnknownOrganization(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgDB := newTestOrganizationDB(t)
|
||||
|
||||
err := orgDB.SetArchived(ctx, accountRef, primitive.NewObjectID(), true, false)
|
||||
err := orgDB.SetArchived(ctx, accountRef, bson.NewObjectID(), true, false)
|
||||
require.Error(t, err)
|
||||
assert.True(t, errors.Is(err, merrors.ErrNoData))
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB {
|
||||
Logger: logger,
|
||||
Repository: repo,
|
||||
}
|
||||
dbImp.SetDeleter(func(ctx context.Context, objectRef primitive.ObjectID) error {
|
||||
dbImp.SetDeleter(func(ctx context.Context, objectRef bson.ObjectID) error {
|
||||
return repo.Delete(ctx, objectRef)
|
||||
})
|
||||
|
||||
@@ -79,7 +79,7 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB {
|
||||
ProtectedDBImp: auth.ProtectedDBImp[*model.Organization]{
|
||||
DBImp: dbImp,
|
||||
Enforcer: allowAllEnforcer{},
|
||||
PermissionRef: primitive.NewObjectID(),
|
||||
PermissionRef: bson.NewObjectID(),
|
||||
Collection: mservice.Organizations,
|
||||
},
|
||||
}
|
||||
@@ -87,35 +87,35 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB {
|
||||
|
||||
type allowAllEnforcer struct{}
|
||||
|
||||
func (allowAllEnforcer) Enforce(context.Context, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, model.Action) (bool, error) {
|
||||
func (allowAllEnforcer) Enforce(context.Context, bson.ObjectID, bson.ObjectID, bson.ObjectID, bson.ObjectID, model.Action) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (allowAllEnforcer) EnforceBatch(_ context.Context, objects []model.PermissionBoundStorable, _ primitive.ObjectID, _ model.Action) (map[primitive.ObjectID]bool, error) {
|
||||
result := make(map[primitive.ObjectID]bool, len(objects))
|
||||
func (allowAllEnforcer) EnforceBatch(_ context.Context, objects []model.PermissionBoundStorable, _ bson.ObjectID, _ model.Action) (map[bson.ObjectID]bool, error) {
|
||||
result := make(map[bson.ObjectID]bool, len(objects))
|
||||
for _, obj := range objects {
|
||||
result[*obj.GetID()] = true
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (allowAllEnforcer) GetRoles(context.Context, primitive.ObjectID, primitive.ObjectID) ([]model.Role, error) {
|
||||
func (allowAllEnforcer) GetRoles(context.Context, bson.ObjectID, bson.ObjectID) ([]model.Role, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (allowAllEnforcer) GetPermissions(context.Context, primitive.ObjectID, primitive.ObjectID) ([]model.Role, []model.Permission, error) {
|
||||
func (allowAllEnforcer) GetPermissions(context.Context, bson.ObjectID, bson.ObjectID) ([]model.Role, []model.Permission, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
type memoryOrganizationRepository struct {
|
||||
mu sync.RWMutex
|
||||
data map[primitive.ObjectID]*model.Organization
|
||||
order []primitive.ObjectID
|
||||
data map[bson.ObjectID]*model.Organization
|
||||
order []bson.ObjectID
|
||||
}
|
||||
|
||||
func newMemoryOrganizationRepository() *memoryOrganizationRepository {
|
||||
return &memoryOrganizationRepository{
|
||||
data: make(map[primitive.ObjectID]*model.Organization),
|
||||
data: make(map[bson.ObjectID]*model.Organization),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func (m *memoryOrganizationRepository) Insert(_ context.Context, obj storable.St
|
||||
return merrors.InvalidDataType("expected organization")
|
||||
}
|
||||
id := org.GetID()
|
||||
if id == nil || *id == primitive.NilObjectID {
|
||||
if id == nil || *id == bson.NilObjectID {
|
||||
return merrors.InvalidArgument("organization ID must be set")
|
||||
}
|
||||
if _, exists := m.data[*id]; exists {
|
||||
@@ -152,7 +152,7 @@ func (m *memoryOrganizationRepository) InsertMany(ctx context.Context, objects [
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memoryOrganizationRepository) Get(_ context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
func (m *memoryOrganizationRepository) Get(_ context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
@@ -207,7 +207,7 @@ func (m *memoryOrganizationRepository) Update(_ context.Context, obj storable.St
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memoryOrganizationRepository) Patch(context.Context, primitive.ObjectID, builder.Patch) error {
|
||||
func (m *memoryOrganizationRepository) Patch(context.Context, bson.ObjectID, builder.Patch) error {
|
||||
return merrors.NotImplemented("Patch is not supported in memory repository")
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ func (m *memoryOrganizationRepository) PatchMany(context.Context, builder.Query,
|
||||
return 0, merrors.NotImplemented("PatchMany is not supported in memory repository")
|
||||
}
|
||||
|
||||
func (m *memoryOrganizationRepository) Delete(_ context.Context, id primitive.ObjectID) error {
|
||||
func (m *memoryOrganizationRepository) Delete(_ context.Context, id bson.ObjectID) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if _, exists := m.data[id]; !exists {
|
||||
@@ -233,11 +233,11 @@ func (m *memoryOrganizationRepository) CreateIndex(*ri.Definition) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memoryOrganizationRepository) ListIDs(_ context.Context, query builder.Query) ([]primitive.ObjectID, error) {
|
||||
func (m *memoryOrganizationRepository) ListIDs(_ context.Context, query builder.Query) ([]bson.ObjectID, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
var ids []primitive.ObjectID
|
||||
var ids []bson.ObjectID
|
||||
for _, id := range m.order {
|
||||
if org, ok := m.data[id]; ok && m.matchesQuery(query, org) {
|
||||
ids = append(ids, id)
|
||||
@@ -277,7 +277,7 @@ func (m *memoryOrganizationRepository) matchesQuery(query builder.Query, org *mo
|
||||
for _, elem := range query.BuildQuery() {
|
||||
switch elem.Key {
|
||||
case storable.IDField:
|
||||
id, ok := elem.Value.(primitive.ObjectID)
|
||||
id, ok := elem.Value.(bson.ObjectID)
|
||||
if !ok || *org.GetID() != id {
|
||||
return false
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func (m *memoryOrganizationRepository) matchesQuery(query builder.Query, org *mo
|
||||
func cloneOrganization(src *model.Organization) *model.Organization {
|
||||
dst := *src
|
||||
if len(src.Members) > 0 {
|
||||
dst.Members = append([]primitive.ObjectID{}, src.Members...)
|
||||
dst.Members = append([]bson.ObjectID{}, src.Members...)
|
||||
}
|
||||
return &dst
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func (db *PaymentMethodsDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef primitive.ObjectID, isArchived, cascade bool) error {
|
||||
func (db *PaymentMethodsDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef bson.ObjectID, isArchived, cascade bool) error {
|
||||
// Use the ArchivableDB for the main archiving logic
|
||||
if err := db.ArchivableDB.SetArchived(ctx, accountRef, objectRef, isArchived); err != nil {
|
||||
db.DBImp.Logger.Warn("Failed to chnage object archive status", zap.Error(err),
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mauth "github.com/tech/sendico/pkg/mutil/db/auth"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *PaymentMethodsDB) List(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) {
|
||||
func (db *PaymentMethodsDB) List(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) {
|
||||
res, err := mauth.GetProtectedObjects[model.PaymentMethod](
|
||||
ctx,
|
||||
db.DBImp.Logger,
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *PoliciesDB) All(ctx context.Context, organizationRef primitive.ObjectID) ([]model.PolicyDescription, error) {
|
||||
func (db *PoliciesDB) All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error) {
|
||||
// all documents
|
||||
filter := repository.Query().Or(
|
||||
repository.Filter(storable.OrganizationRefField, nil),
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type PoliciesDB struct {
|
||||
|
||||
@@ -14,17 +14,19 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
|
||||
// Model package (contains PolicyDescription + Describable)
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
|
||||
// Testcontainers
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -114,7 +116,7 @@ func TestPoliciesDB(t *testing.T) {
|
||||
cleanupCollection(t, ctx, db)
|
||||
|
||||
// Attempt to get a non-existent ID
|
||||
nonExistentID := primitive.NewObjectID()
|
||||
nonExistentID := bson.NewObjectID()
|
||||
result := &model.PolicyDescription{}
|
||||
err := pdb.Get(ctx, nonExistentID, result)
|
||||
assert.Error(t, err)
|
||||
@@ -234,8 +236,8 @@ func TestPoliciesDB(t *testing.T) {
|
||||
cleanupCollection(t, ctx, db)
|
||||
|
||||
// Insert some policies (orgA, orgB, nil org)
|
||||
orgA := primitive.NewObjectID()
|
||||
orgB := primitive.NewObjectID()
|
||||
orgA := bson.NewObjectID()
|
||||
orgB := bson.NewObjectID()
|
||||
|
||||
descA := "Org A policy"
|
||||
policyA := &model.PolicyDescription{
|
||||
@@ -272,7 +274,7 @@ func TestPoliciesDB(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resultsA, 2) // orgA + built-in
|
||||
|
||||
var idsA []primitive.ObjectID
|
||||
var idsA []bson.ObjectID
|
||||
for _, r := range resultsA {
|
||||
idsA = append(idsA, r.ID)
|
||||
}
|
||||
@@ -284,7 +286,7 @@ func TestPoliciesDB(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resultsB, 2) // orgB + built-in
|
||||
|
||||
var idsB []primitive.ObjectID
|
||||
var idsB []bson.ObjectID
|
||||
for _, r := range resultsB {
|
||||
idsB = append(idsB, r.ID)
|
||||
}
|
||||
@@ -322,11 +324,11 @@ func TestPoliciesDB(t *testing.T) {
|
||||
require.NoError(t, pdb.Create(ctx, pol3))
|
||||
|
||||
// 1) Request pol1, pol2
|
||||
results12, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol2.ID})
|
||||
results12, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol2.ID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results12, 2)
|
||||
// IDs might be out of order, so we do a set-like check
|
||||
var set12 []primitive.ObjectID
|
||||
var set12 []bson.ObjectID
|
||||
for _, r := range results12 {
|
||||
set12 = append(set12, r.ID)
|
||||
}
|
||||
@@ -334,11 +336,11 @@ func TestPoliciesDB(t *testing.T) {
|
||||
assert.Contains(t, set12, pol2.ID)
|
||||
|
||||
// 2) Request pol1, pol3, plus a random ID
|
||||
fakeID := primitive.NewObjectID()
|
||||
results13Fake, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol3.ID, fakeID})
|
||||
fakeID := bson.NewObjectID()
|
||||
results13Fake, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol3.ID, fakeID})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results13Fake, 2) // pol1 + pol3 only
|
||||
var set13Fake []primitive.ObjectID
|
||||
var set13Fake []bson.ObjectID
|
||||
for _, r := range results13Fake {
|
||||
set13Fake = append(set13Fake, r.ID)
|
||||
}
|
||||
@@ -346,7 +348,7 @@ func TestPoliciesDB(t *testing.T) {
|
||||
assert.Contains(t, set13Fake, pol3.ID)
|
||||
|
||||
// 3) Request with empty slice => expect no results
|
||||
resultsEmpty, err := pdb.Policies(ctx, []primitive.ObjectID{})
|
||||
resultsEmpty, err := pdb.Policies(ctx, []bson.ObjectID{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, resultsEmpty, 0)
|
||||
})
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *PoliciesDB) Policies(ctx context.Context, refs []primitive.ObjectID) ([]model.PolicyDescription, error) {
|
||||
func (db *PoliciesDB) Policies(ctx context.Context, refs []bson.ObjectID) ([]model.PolicyDescription, error) {
|
||||
if len(refs) == 0 {
|
||||
return []model.PolicyDescription{}, nil
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef primitive.ObjectID, isArchived, cascade bool) error {
|
||||
func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef bson.ObjectID, isArchived, cascade bool) error {
|
||||
// Use the ArchivableDB for the main archiving logic
|
||||
if err := db.ArchivableDB.SetArchived(ctx, accountRef, objectRef, isArchived); err != nil {
|
||||
db.DBImp.Logger.Warn("Failed to change recipient archive status", zap.Error(err),
|
||||
@@ -32,7 +32,7 @@ func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organization
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *RecipientDB) setArchivedPaymentMethods(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, archived bool) error {
|
||||
func (db *RecipientDB) setArchivedPaymentMethods(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, archived bool) error {
|
||||
db.DBImp.Logger.Debug("Setting archived status for recipient payment methods", mzap.ObjRef("recipient_ref", recipientRef), zap.Bool("archived", archived))
|
||||
|
||||
db.DBImp.Logger.Debug("Applying archived status to payment methods for recipient", mzap.ObjRef("recipient_ref", recipientRef))
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type RecipientDB struct {
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mauth "github.com/tech/sendico/pkg/mutil/db/auth"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *RecipientDB) List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) {
|
||||
func (db *RecipientDB) List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) {
|
||||
res, err := mauth.GetProtectedObjects[model.Recipient](
|
||||
ctx,
|
||||
db.DBImp.Logger,
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"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/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -67,12 +67,12 @@ func (db *RefreshTokenDB) Update(ctx context.Context, rt *model.RefreshToken) er
|
||||
return db.Patch(ctx, *rt.GetID(), patch)
|
||||
}
|
||||
|
||||
func (db *RefreshTokenDB) Delete(ctx context.Context, tokenRef primitive.ObjectID) error {
|
||||
func (db *RefreshTokenDB) Delete(ctx context.Context, tokenRef bson.ObjectID) error {
|
||||
db.Logger.Info("Deleting refresh token", mzap.ObjRef("refresh_token_ref", tokenRef))
|
||||
return db.DBImp.Delete(ctx, tokenRef)
|
||||
}
|
||||
|
||||
func (db *RefreshTokenDB) Revoke(ctx context.Context, accountRef primitive.ObjectID, session *model.SessionIdentifier) error {
|
||||
func (db *RefreshTokenDB) Revoke(ctx context.Context, accountRef bson.ObjectID, session *model.SessionIdentifier) error {
|
||||
var rt model.RefreshToken
|
||||
f := filterByAccount(accountRef, session)
|
||||
if err := db.Repository.FindOneByFilter(ctx, f, &rt); err != nil {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func filterByClientId(clientID string) builder.Query {
|
||||
@@ -20,6 +20,6 @@ func filter(session *model.SessionIdentifier) builder.Query {
|
||||
return filter
|
||||
}
|
||||
|
||||
func filterByAccount(accountRef primitive.ObjectID, session *model.SessionIdentifier) builder.Query {
|
||||
func filterByAccount(accountRef bson.ObjectID, session *model.SessionIdentifier) builder.Query {
|
||||
return filter(session).And(repository.Query().Comparison(repository.AccountField(), builder.Eq, accountRef))
|
||||
}
|
||||
|
||||
@@ -21,10 +21,9 @@ import (
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*refreshtokensdb.RefreshTokenDB, func()) {
|
||||
@@ -71,7 +70,7 @@ func setupTestDBWithMongo(t *testing.T) (*refreshtokensdb.RefreshTokenDB, *mongo
|
||||
return db, database, cleanup
|
||||
}
|
||||
|
||||
func createTestRefreshToken(accountRef primitive.ObjectID, clientID, deviceID, token string) *model.RefreshToken {
|
||||
func createTestRefreshToken(accountRef bson.ObjectID, clientID, deviceID, token string) *model.RefreshToken {
|
||||
return &model.RefreshToken{
|
||||
ClientRefreshToken: model.ClientRefreshToken{
|
||||
SessionIdentifier: model.SessionIdentifier{
|
||||
@@ -99,7 +98,7 @@ func TestRefreshTokenDB_AuthenticationFlow(t *testing.T) {
|
||||
|
||||
t.Run("Complete_User_Authentication_Flow", func(t *testing.T) {
|
||||
// Setup: Create user and client
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-desktop-chrome"
|
||||
token := "refresh_token_12345"
|
||||
@@ -141,7 +140,7 @@ func TestRefreshTokenDB_AuthenticationFlow(t *testing.T) {
|
||||
|
||||
t.Run("Manual_Token_Revocation_Workaround", func(t *testing.T) {
|
||||
// Test manual revocation by directly updating the token
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-desktop-chrome"
|
||||
token := "manual_revoke_token_123"
|
||||
@@ -178,7 +177,7 @@ func TestRefreshTokenDB_MultiDeviceManagement(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("User_With_Multiple_Devices", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "mobile-app"
|
||||
|
||||
// User logs in from phone
|
||||
@@ -241,7 +240,7 @@ func TestRefreshTokenDB_TokenRotation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Token_Rotation_On_Use", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-browser"
|
||||
initialToken := "initial_token_123"
|
||||
@@ -298,7 +297,7 @@ func TestRefreshTokenDB_SessionReplacement(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("User_Login_From_Same_Device_Twice", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-laptop"
|
||||
|
||||
@@ -340,7 +339,7 @@ func TestRefreshTokenDB_SessionReplacement(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Create_After_GlobalRevocation_AllowsNewActive", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-laptop"
|
||||
|
||||
@@ -407,7 +406,7 @@ func TestRefreshTokenDB_ClientManagement(t *testing.T) {
|
||||
// Note: Client management is handled by a separate client database
|
||||
// This test verifies that refresh tokens work with different client IDs
|
||||
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
|
||||
// Create refresh tokens for different clients
|
||||
webToken := createTestRefreshToken(userID, "web-app", "device1", "token1")
|
||||
@@ -454,7 +453,7 @@ func TestRefreshTokenDB_SecurityScenarios(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Token_Hijacking_Prevention", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-browser"
|
||||
token := "hijacked_token_123"
|
||||
@@ -509,7 +508,7 @@ func TestRefreshTokenDB_ExpiredTokenHandling(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Expired_Token_Cleanup", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-device"
|
||||
token := "expired_token_123"
|
||||
@@ -548,7 +547,7 @@ func TestRefreshTokenDB_ConcurrentAccess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Concurrent_Token_Usage", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "user-device"
|
||||
token := "concurrent_token_123"
|
||||
@@ -594,7 +593,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Delete_Token_By_ID", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
refreshToken := createTestRefreshToken(userID, "web-app", "device-1", "token_123")
|
||||
err := db.Create(ctx, refreshToken)
|
||||
require.NoError(t, err)
|
||||
@@ -613,7 +612,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Revoke_Non_Existent_Token", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
session := &model.SessionIdentifier{
|
||||
ClientID: "non-existent-client",
|
||||
DeviceID: "non-existent-device",
|
||||
@@ -625,7 +624,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("RevokeAll_No_Other_Devices", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
deviceID := "only-device"
|
||||
|
||||
@@ -659,8 +658,8 @@ func TestRefreshTokenDB_DatabaseIndexes(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Unique_Token_Constraint", func(t *testing.T) {
|
||||
userID1 := primitive.NewObjectID()
|
||||
userID2 := primitive.NewObjectID()
|
||||
userID1 := bson.NewObjectID()
|
||||
userID2 := bson.NewObjectID()
|
||||
token := "duplicate_token_123"
|
||||
|
||||
// Create first token
|
||||
@@ -676,7 +675,7 @@ func TestRefreshTokenDB_DatabaseIndexes(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query_Performance_By_Revocation_Status", func(t *testing.T) {
|
||||
userID := primitive.NewObjectID()
|
||||
userID := bson.NewObjectID()
|
||||
clientID := "web-app"
|
||||
|
||||
// Create multiple tokens
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *RefreshTokenDB) RevokeAll(ctx context.Context, accountRef primitive.ObjectID, deviceID string) error {
|
||||
func (db *RefreshTokenDB) RevokeAll(ctx context.Context, accountRef bson.ObjectID, deviceID string) error {
|
||||
query := repository.Query().
|
||||
Filter(repository.AccountField(), accountRef).
|
||||
And(repository.Query().Comparison(repository.Field("deviceId"), builder.Ne, deviceID)).
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type literalAccumulatorImp struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type aliasImp struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type arrayImp struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type literalExpression struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type condImp struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type groupAccumulatorImp struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type patchBuilder struct {
|
||||
|
||||
@@ -3,8 +3,8 @@ package builderimp
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type unwindOpts = builder.UnwindOpts
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestNewPipelineImp(t *testing.T) {
|
||||
@@ -454,7 +454,7 @@ func (m *MockQuery) Offset(offset *int64) builder.Query
|
||||
func (m *MockQuery) Archived(isArchived *bool) builder.Query { return m }
|
||||
func (m *MockQuery) BuildPipeline() bson.D { return m.buildPipeline }
|
||||
func (m *MockQuery) BuildQuery() bson.D { return bson.D{} }
|
||||
func (m *MockQuery) BuildOptions() *options.FindOptions { return &options.FindOptions{} }
|
||||
func (m *MockQuery) BuildOptions() *options.FindOptionsBuilder { return &options.FindOptionsBuilder{} }
|
||||
|
||||
type MockField struct {
|
||||
build string
|
||||
|
||||
@@ -2,7 +2,7 @@ package builderimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// projectionExprImp is a concrete implementation of builder.Projection
|
||||
|
||||
@@ -5,9 +5,8 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
type QueryImp struct {
|
||||
@@ -51,7 +50,7 @@ func (b *QueryImp) Expression(value builder.Expression) builder.Query {
|
||||
}
|
||||
|
||||
func (b *QueryImp) RegEx(field builder.Field, pattern, options string) builder.Query {
|
||||
b.filter = append(b.filter, bson.E{Key: field.Build(), Value: primitive.Regex{Pattern: pattern, Options: options}})
|
||||
b.filter = append(b.filter, bson.E{Key: field.Build(), Value: bson.Regex{Pattern: pattern, Options: options}})
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ func (b *QueryImp) Offset(offset *int64) builder.Query {
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *QueryImp) BuildOptions() *options.FindOptions {
|
||||
func (b *QueryImp) BuildOptions() *options.FindOptionsBuilder {
|
||||
opts := options.Find()
|
||||
if b.limit != nil {
|
||||
opts.SetLimit(*b.limit)
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
ri "github.com/tech/sendico/pkg/db/repository/index"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"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"
|
||||
)
|
||||
|
||||
func (r *MongoRepository) CreateIndex(def *ri.Definition) error {
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestCreateIndex_WithPartialFilter(t *testing.T) {
|
||||
|
||||
@@ -10,10 +10,9 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"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"
|
||||
)
|
||||
|
||||
type MongoRepository struct {
|
||||
@@ -21,7 +20,7 @@ type MongoRepository struct {
|
||||
collection *mongo.Collection
|
||||
}
|
||||
|
||||
func idFilter(id primitive.ObjectID) bson.D {
|
||||
func idFilter(id bson.ObjectID) bson.D {
|
||||
return bson.D{
|
||||
{Key: storable.IDField, Value: id},
|
||||
}
|
||||
@@ -40,7 +39,7 @@ func (r *MongoRepository) Collection() string {
|
||||
|
||||
func (r *MongoRepository) Insert(ctx context.Context, obj storable.Storable, getFilter builder.Query) error {
|
||||
if (obj.GetID() == nil) || (obj.GetID().IsZero()) {
|
||||
obj.SetID(primitive.NewObjectID())
|
||||
obj.SetID(bson.NewObjectID())
|
||||
}
|
||||
obj.Update()
|
||||
_, err := r.collection.InsertOne(ctx, obj)
|
||||
@@ -63,7 +62,7 @@ func (r *MongoRepository) InsertMany(ctx context.Context, objects []storable.Sto
|
||||
docs := make([]interface{}, len(objects))
|
||||
for i, obj := range objects {
|
||||
if (obj.GetID() == nil) || (obj.GetID().IsZero()) {
|
||||
obj.SetID(primitive.NewObjectID())
|
||||
obj.SetID(bson.NewObjectID())
|
||||
}
|
||||
obj.Update()
|
||||
docs[i] = obj
|
||||
@@ -81,7 +80,7 @@ func (r *MongoRepository) findOneByFilterImp(ctx context.Context, filter bson.D,
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *MongoRepository) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error {
|
||||
func (r *MongoRepository) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error {
|
||||
if id.IsZero() {
|
||||
return merrors.InvalidArgument("zero id provided while fetching "+result.Collection(), "id")
|
||||
}
|
||||
@@ -132,7 +131,7 @@ func (r *MongoRepository) Update(ctx context.Context, obj storable.Storable) err
|
||||
return r.collection.FindOneAndReplace(ctx, idFilter(*obj.GetID()), obj).Err()
|
||||
}
|
||||
|
||||
func (r *MongoRepository) Patch(ctx context.Context, id primitive.ObjectID, patch builder.Patch) error {
|
||||
func (r *MongoRepository) Patch(ctx context.Context, id bson.ObjectID, patch builder.Patch) error {
|
||||
if id.IsZero() {
|
||||
return merrors.InvalidArgument("zero id provided while patching", "id")
|
||||
}
|
||||
@@ -148,7 +147,7 @@ func (r *MongoRepository) PatchMany(ctx context.Context, query builder.Query, pa
|
||||
return int(result.ModifiedCount), nil
|
||||
}
|
||||
|
||||
func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) {
|
||||
func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) {
|
||||
filter := query.BuildQuery()
|
||||
findOptions := options.Find().SetProjection(bson.M{storable.IDField: 1})
|
||||
|
||||
@@ -158,10 +157,10 @@ func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]p
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
var ids []primitive.ObjectID
|
||||
var ids []bson.ObjectID
|
||||
for cursor.Next(ctx) {
|
||||
var doc struct {
|
||||
ID primitive.ObjectID `bson:"_id"`
|
||||
ID bson.ObjectID `bson:"_id"`
|
||||
}
|
||||
if err := cursor.Decode(&doc); err != nil {
|
||||
return nil, err
|
||||
@@ -235,7 +234,7 @@ func (r *MongoRepository) ListAccountBound(ctx context.Context, query builder.Qu
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *MongoRepository) Delete(ctx context.Context, id primitive.ObjectID) error {
|
||||
func (r *MongoRepository) Delete(ctx context.Context, id bson.ObjectID) error {
|
||||
_, err := r.collection.DeleteOne(ctx, idFilter(id))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,19 +9,18 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp/builderimp"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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"
|
||||
)
|
||||
|
||||
func TestMongoRepository_Insert(t *testing.T) {
|
||||
@@ -63,7 +62,7 @@ func TestMongoRepository_Insert(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Insert_WithExistingID", func(t *testing.T) {
|
||||
existingID := primitive.NewObjectID()
|
||||
existingID := bson.NewObjectID()
|
||||
testObj := &TestObject{Name: "testInsertWithID"}
|
||||
testObj.SetID(existingID)
|
||||
|
||||
@@ -158,7 +157,7 @@ func TestMongoRepository_Update(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Update_NonExistentObject", func(t *testing.T) {
|
||||
nonExistentID := primitive.NewObjectID()
|
||||
nonExistentID := bson.NewObjectID()
|
||||
testObj := &TestObject{Name: "nonExistent"}
|
||||
testObj.SetID(nonExistentID)
|
||||
|
||||
@@ -210,7 +209,7 @@ func TestMongoRepository_Delete(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Delete_NonExistentObject", func(t *testing.T) {
|
||||
nonExistentID := primitive.NewObjectID()
|
||||
nonExistentID := bson.NewObjectID()
|
||||
|
||||
err := repository.Delete(ctx, nonExistentID)
|
||||
// Delete should not return error even if object doesn't exist
|
||||
@@ -473,19 +472,19 @@ func TestMongoRepository_ListPermissionBound(t *testing.T) {
|
||||
|
||||
t.Run("ListPermissionBound_WithData", func(t *testing.T) {
|
||||
// Insert test objects with permission bound data
|
||||
orgID := primitive.NewObjectID()
|
||||
orgID := bson.NewObjectID()
|
||||
|
||||
// Insert documents directly with permission bound fields
|
||||
_, err := db.Collection("testcollection").InsertMany(ctx, []interface{}{
|
||||
bson.M{
|
||||
"_id": primitive.NewObjectID(),
|
||||
"_id": bson.NewObjectID(),
|
||||
"organizationRef": orgID,
|
||||
"permissionRef": primitive.NewObjectID(),
|
||||
"permissionRef": bson.NewObjectID(),
|
||||
},
|
||||
bson.M{
|
||||
"_id": primitive.NewObjectID(),
|
||||
"_id": bson.NewObjectID(),
|
||||
"organizationRef": orgID,
|
||||
"permissionRef": primitive.NewObjectID(),
|
||||
"permissionRef": bson.NewObjectID(),
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -504,7 +503,7 @@ func TestMongoRepository_ListPermissionBound(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("ListPermissionBound_EmptyResult", func(t *testing.T) {
|
||||
nonExistentOrgID := primitive.NewObjectID()
|
||||
nonExistentOrgID := bson.NewObjectID()
|
||||
query := builderimp.NewQueryImp().Comparison(builderimp.NewFieldImp("organizationRef"), builder.Eq, nonExistentOrgID)
|
||||
|
||||
results, err := repository.ListPermissionBound(ctx, query)
|
||||
@@ -544,7 +543,7 @@ func TestMongoRepository_UpdateTimestamp(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set ID and initial timestamps
|
||||
obj.SetID(primitive.NewObjectID())
|
||||
obj.SetID(bson.NewObjectID())
|
||||
originalCreatedAt := obj.CreatedAt
|
||||
originalUpdatedAt := obj.UpdatedAt
|
||||
|
||||
|
||||
@@ -8,16 +8,15 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
func TestMongoRepository_InsertMany(t *testing.T) {
|
||||
@@ -75,8 +74,8 @@ func TestMongoRepository_InsertMany(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InsertMany_WithExistingIDs", func(t *testing.T) {
|
||||
id1 := primitive.NewObjectID()
|
||||
id2 := primitive.NewObjectID()
|
||||
id1 := bson.NewObjectID()
|
||||
id2 := bson.NewObjectID()
|
||||
|
||||
objects := []storable.Storable{
|
||||
&TestObject{Base: storable.Base{ID: id1}, Name: "preassigned1"},
|
||||
@@ -116,7 +115,7 @@ func TestMongoRepository_InsertMany(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InsertMany_DuplicateKey", func(t *testing.T) {
|
||||
id := primitive.NewObjectID()
|
||||
id := bson.NewObjectID()
|
||||
|
||||
// Insert first object
|
||||
obj1 := &TestObject{Base: storable.Base{ID: id}, Name: "original"}
|
||||
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
func TestMongoRepository_PatchOperations(t *testing.T) {
|
||||
|
||||
@@ -9,19 +9,19 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp"
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp/builderimp"
|
||||
"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"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/mongodb"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"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"
|
||||
)
|
||||
|
||||
type TestObject struct {
|
||||
@@ -92,7 +92,7 @@ func TestMongoRepository_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Get_NotFound", func(t *testing.T) {
|
||||
nonExistentID := primitive.NewObjectID()
|
||||
nonExistentID := bson.NewObjectID()
|
||||
result := &TestObject{}
|
||||
|
||||
err := repository.Get(ctx, nonExistentID, result)
|
||||
@@ -101,7 +101,7 @@ func TestMongoRepository_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Get_InvalidID", func(t *testing.T) {
|
||||
invalidID := primitive.ObjectID{} // zero value
|
||||
invalidID := bson.ObjectID{} // zero value
|
||||
result := &TestObject{}
|
||||
|
||||
err := repository.Get(ctx, invalidID, result)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type RolesDB struct {
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *RolesDB) List(ctx context.Context, organizationRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) {
|
||||
func (db *RolesDB) List(ctx context.Context, organizationRef bson.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) {
|
||||
filter := repository.OrgFilter(organizationRef)
|
||||
return mutil.GetObjects[model.RoleDescription](ctx, db.Logger, filter, cursor, db.Repository)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (db *RolesDB) Roles(ctx context.Context, refs []primitive.ObjectID) ([]model.RoleDescription, error) {
|
||||
func (db *RolesDB) Roles(ctx context.Context, refs []bson.ObjectID) ([]model.RoleDescription, error) {
|
||||
filter := repository.Query().In(repository.IDField(), refs)
|
||||
return mutil.GetObjects[model.RoleDescription](ctx, db.Logger, filter, nil, db.Repository)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package transactionimp
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type MongoTransactionFactory struct {
|
||||
|
||||
@@ -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 MongoTransaction struct {
|
||||
@@ -18,8 +18,8 @@ func (mt *MongoTransaction) Execute(ctx context.Context, cb transaction.Callback
|
||||
}
|
||||
defer session.EndSession(ctx)
|
||||
|
||||
callback := func(sessCtx mongo.SessionContext) (any, error) {
|
||||
return cb(sessCtx)
|
||||
callback := func(c context.Context) (any, error) {
|
||||
return cb(c)
|
||||
}
|
||||
|
||||
return session.WithTransaction(ctx, callback)
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
tsoptions "github.com/tech/sendico/pkg/db/tseries/options"
|
||||
tspoint "github.com/tech/sendico/pkg/db/tseries/point"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
type TimeSeries struct {
|
||||
@@ -26,12 +26,13 @@ func NewMongoTimeSeriesCollection(ctx context.Context, db *mongo.Database, tsOpt
|
||||
}
|
||||
// Configure time-series options
|
||||
granularity := tsOpts.Granularity.String()
|
||||
ts := &options.TimeSeriesOptions{
|
||||
TimeField: tsOpts.TimeField,
|
||||
Granularity: &granularity,
|
||||
}
|
||||
ts := &options.TimeSeriesOptionsBuilder{}
|
||||
// TimeField: tsOpts.TimeField,
|
||||
// Granularity: &granularity,
|
||||
ts.SetTimeField(tsOpts.TimeField)
|
||||
ts.SetGranularity(granularity)
|
||||
if tsOpts.MetaField != "" {
|
||||
ts.MetaField = &tsOpts.MetaField
|
||||
ts.SetMetaField(tsOpts.MetaField)
|
||||
}
|
||||
|
||||
// Collection options
|
||||
|
||||
@@ -5,15 +5,15 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/auth"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
auth.ProtectedDB[*model.Invitation]
|
||||
GetPublic(ctx context.Context, invitationRef primitive.ObjectID) (*model.PublicInvitation, error)
|
||||
Accept(ctx context.Context, invitationRef primitive.ObjectID) error
|
||||
Decline(ctx context.Context, invitationRef primitive.ObjectID) error
|
||||
List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error)
|
||||
DeleteCascade(ctx context.Context, accountRef, statusRef primitive.ObjectID) error
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef primitive.ObjectID, archived, cascade bool) error
|
||||
GetPublic(ctx context.Context, invitationRef bson.ObjectID) (*model.PublicInvitation, error)
|
||||
Accept(ctx context.Context, invitationRef bson.ObjectID) error
|
||||
Decline(ctx context.Context, invitationRef bson.ObjectID) error
|
||||
List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error)
|
||||
DeleteCascade(ctx context.Context, accountRef, statusRef bson.ObjectID) error
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef bson.ObjectID, archived, cascade bool) error
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/auth"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// DB is the interface which must be implemented by all db drivers
|
||||
type DB interface {
|
||||
auth.ProtectedDB[*model.Organization]
|
||||
List(ctx context.Context, accountRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error)
|
||||
ListOwned(ctx context.Context, accountRef primitive.ObjectID) ([]model.Organization, error)
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef primitive.ObjectID, archived, cascade bool) error
|
||||
List(ctx context.Context, accountRef bson.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error)
|
||||
ListOwned(ctx context.Context, accountRef bson.ObjectID) ([]model.Organization, error)
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef bson.ObjectID, archived, cascade bool) error
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/auth"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
auth.ProtectedDB[*model.PaymentMethod]
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, methodRef primitive.ObjectID, archived, cascade bool) error
|
||||
List(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error)
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, methodRef bson.ObjectID, archived, cascade bool) error
|
||||
List(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error)
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/template"
|
||||
"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"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
template.DB[*model.PolicyDescription]
|
||||
All(ctx context.Context, organizationRef primitive.ObjectID) ([]model.PolicyDescription, error)
|
||||
Policies(ctx context.Context, refs []primitive.ObjectID) ([]model.PolicyDescription, error)
|
||||
All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error)
|
||||
Policies(ctx context.Context, refs []bson.ObjectID) ([]model.PolicyDescription, error)
|
||||
GetBuiltInPolicy(ctx context.Context, resourceType mservice.Type, policy *model.PolicyDescription) error
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/auth"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
auth.ProtectedDB[*model.Recipient]
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, archived, cascade bool) error
|
||||
List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error)
|
||||
SetArchived(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, archived, cascade bool) error
|
||||
List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error)
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/template"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
template.DB[*model.RefreshToken]
|
||||
Revoke(ctx context.Context, accountRef primitive.ObjectID, session *model.SessionIdentifier) error
|
||||
RevokeAll(ctx context.Context, accountRef primitive.ObjectID, deviceID string) error
|
||||
Revoke(ctx context.Context, accountRef bson.ObjectID, session *model.SessionIdentifier) error
|
||||
RevokeAll(ctx context.Context, accountRef bson.ObjectID, deviceID string) error
|
||||
GetByCRT(ctx context.Context, t *model.ClientRefreshToken) (*model.RefreshToken, error)
|
||||
GetClient(ctx context.Context, clientID string) (*model.Client, error)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package repository
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// AccountBoundFilter provides factory methods for creating account-bound filters
|
||||
@@ -19,7 +19,7 @@ func NewAccountBoundFilter() *AccountBoundFilter {
|
||||
// - accountRef matches the provided accountRef, OR
|
||||
// - accountRef is nil/null, OR
|
||||
// - accountRef field doesn't exist
|
||||
func (f *AccountBoundFilter) WithoutOrg(accountRef primitive.ObjectID) builder.Query {
|
||||
func (f *AccountBoundFilter) WithoutOrg(accountRef bson.ObjectID) builder.Query {
|
||||
return Query().Or(
|
||||
AccountFilter(accountRef),
|
||||
Filter(model.AccountRefField, nil),
|
||||
@@ -33,7 +33,7 @@ func (f *AccountBoundFilter) WithoutOrg(accountRef primitive.ObjectID) builder.Q
|
||||
// - accountRef is nil/null, OR
|
||||
// - accountRef field doesn't exist
|
||||
// AND combines with organization filter
|
||||
func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef primitive.ObjectID) builder.Query {
|
||||
func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query {
|
||||
return Query().And(
|
||||
OrgFilter(organizationRef),
|
||||
f.WithoutOrg(accountRef),
|
||||
@@ -41,13 +41,13 @@ func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef primitive.Objec
|
||||
}
|
||||
|
||||
// WithQuery creates a filter for account-bound objects with additional query and organization filter
|
||||
func (f *AccountBoundFilter) WithQuery(accountRef, organizationRef primitive.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
func (f *AccountBoundFilter) WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
accountQuery := f.WithOrg(accountRef, organizationRef)
|
||||
return additionalQuery.And(accountQuery)
|
||||
}
|
||||
|
||||
// WithQueryNoOrg creates a filter for account-bound objects with additional query but no org filter
|
||||
func (f *AccountBoundFilter) WithQueryNoOrg(accountRef primitive.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
func (f *AccountBoundFilter) WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
accountQuery := f.WithoutOrg(accountRef)
|
||||
return additionalQuery.And(accountQuery)
|
||||
}
|
||||
@@ -58,21 +58,21 @@ var DefaultAccountBoundFilter = NewAccountBoundFilter()
|
||||
// Convenience functions that use the global factory instance
|
||||
|
||||
// WithOrg is a convenience function that uses the default factory
|
||||
func WithOrg(accountRef, organizationRef primitive.ObjectID) builder.Query {
|
||||
func WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithOrg(accountRef, organizationRef)
|
||||
}
|
||||
|
||||
// WithoutOrg is a convenience function that uses the default factory
|
||||
func WithoutOrg(accountRef primitive.ObjectID) builder.Query {
|
||||
func WithoutOrg(accountRef bson.ObjectID) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithoutOrg(accountRef)
|
||||
}
|
||||
|
||||
// WithQuery is a convenience function that uses the default factory
|
||||
func WithQuery(accountRef, organizationRef primitive.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
func WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithQuery(accountRef, organizationRef, additionalQuery)
|
||||
}
|
||||
|
||||
// WithQueryNoOrg is a convenience function that uses the default factory
|
||||
func WithQueryNoOrg(accountRef primitive.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
func WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithQueryNoOrg(accountRef, additionalQuery)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Accumulator interface {
|
||||
Build() bson.D
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Alias interface {
|
||||
Field() Field
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Array interface {
|
||||
Build() bson.A
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
// Patch defines operations for constructing partial update documents.
|
||||
// Each builder method returns the same Patch instance to allow chaining.
|
||||
|
||||
@@ -2,7 +2,7 @@ package builder
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type Pipeline interface {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Projection interface {
|
||||
Build() bson.D
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
type Query interface {
|
||||
@@ -20,5 +20,5 @@ type Query interface {
|
||||
Archived(isArchived *bool) Query
|
||||
BuildPipeline() bson.D
|
||||
BuildQuery() bson.D
|
||||
BuildOptions() *options.FindOptions
|
||||
BuildOptions() *options.FindOptionsBuilder
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"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"
|
||||
)
|
||||
|
||||
func Query() builder.Query {
|
||||
@@ -52,7 +52,7 @@ func IsArchivedField() builder.Field {
|
||||
return Field(storable.IsArchivedField)
|
||||
}
|
||||
|
||||
func IDFilter(ref primitive.ObjectID) builder.Query {
|
||||
func IDFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(IDField(), ref)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func OrgField() builder.Field {
|
||||
return Field(storable.OrganizationRefField)
|
||||
}
|
||||
|
||||
func OrgFilter(ref primitive.ObjectID) builder.Query {
|
||||
func OrgFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(OrgField(), ref)
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func ProjectField() builder.Field {
|
||||
return Field("projectRef")
|
||||
}
|
||||
|
||||
func ProjectFilter(ref primitive.ObjectID) builder.Query {
|
||||
func ProjectFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(ProjectField(), ref)
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func AccountField() builder.Field {
|
||||
return Field(model.AccountRefField)
|
||||
}
|
||||
|
||||
func AccountFilter(ref primitive.ObjectID) builder.Query {
|
||||
func AccountFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(AccountField(), ref)
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func StatusRefField() builder.Field {
|
||||
return Field("statusRef")
|
||||
}
|
||||
|
||||
func StatusRefFilter(ref primitive.ObjectID) builder.Query {
|
||||
func StatusRefFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(StatusRefField(), ref)
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func PriorityRefField() builder.Field {
|
||||
return Field("priorityRef")
|
||||
}
|
||||
|
||||
func PriorityRefFilter(ref primitive.ObjectID) builder.Query {
|
||||
func PriorityRefFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(PriorityRefField(), ref)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package repository
|
||||
|
||||
import "go.mongodb.org/mongo-driver/mongo"
|
||||
import "go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
||||
type DecodingFunc = func(r *mongo.Cursor) error
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func TestAccountBoundFilter_WithOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
query := factory.WithOrg(accountRef, orgRef)
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestAccountBoundFilter_WithOrg(t *testing.T) {
|
||||
|
||||
func TestAccountBoundFilter_WithoutOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
|
||||
query := factory.WithoutOrg(accountRef)
|
||||
|
||||
@@ -30,8 +30,8 @@ func TestAccountBoundFilter_WithoutOrg(t *testing.T) {
|
||||
|
||||
func TestAccountBoundFilter_WithQuery(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
query := factory.WithQuery(accountRef, orgRef, additionalQuery)
|
||||
@@ -42,7 +42,7 @@ func TestAccountBoundFilter_WithQuery(t *testing.T) {
|
||||
|
||||
func TestAccountBoundFilter_WithQueryNoOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
query := factory.WithQueryNoOrg(accountRef, additionalQuery)
|
||||
@@ -60,8 +60,8 @@ func TestDefaultAccountBoundFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConvenienceFunctions(t *testing.T) {
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
// Test convenience functions
|
||||
@@ -80,8 +80,8 @@ func TestConvenienceFunctions(t *testing.T) {
|
||||
|
||||
func TestFilterFactoryConsistency(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := primitive.NewObjectID()
|
||||
orgRef := primitive.NewObjectID()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
// Test that factory methods and convenience functions produce the same result
|
||||
query1 := factory.WithOrg(accountRef, orgRef)
|
||||
|
||||
@@ -9,8 +9,8 @@ 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/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -24,18 +24,18 @@ type Repository interface {
|
||||
Aggregate(ctx context.Context, builder builder.Pipeline, decoder rd.DecodingFunc) error
|
||||
Insert(ctx context.Context, obj storable.Storable, getFilter builder.Query) error
|
||||
InsertMany(ctx context.Context, objects []storable.Storable) error
|
||||
Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error
|
||||
Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error
|
||||
FindOneByFilter(ctx context.Context, builder builder.Query, result storable.Storable) error
|
||||
FindManyByFilter(ctx context.Context, builder builder.Query, decoder rd.DecodingFunc) error
|
||||
Update(ctx context.Context, obj storable.Storable) error
|
||||
// Patch applies partial updates defined by patch to the document identified by id.
|
||||
Patch(ctx context.Context, id primitive.ObjectID, patch PatchDoc) error
|
||||
Patch(ctx context.Context, id bson.ObjectID, patch PatchDoc) error
|
||||
// PatchMany applies partial updates defined by patch to all documents matching filter and returns the number of updated documents.
|
||||
PatchMany(ctx context.Context, filter FilterQuery, patch PatchDoc) (int, error)
|
||||
Delete(ctx context.Context, id primitive.ObjectID) error
|
||||
Delete(ctx context.Context, id bson.ObjectID) error
|
||||
DeleteMany(ctx context.Context, query builder.Query) error
|
||||
CreateIndex(def *ri.Definition) error
|
||||
ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error)
|
||||
ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error)
|
||||
ListPermissionBound(ctx context.Context, query builder.Query) ([]model.PermissionBoundStorable, error)
|
||||
ListAccountBound(ctx context.Context, query builder.Query) ([]model.AccountBoundStorable, error)
|
||||
Collection() string
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/template"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
template.DB[*model.RoleDescription]
|
||||
Roles(ctx context.Context, refs []primitive.ObjectID) ([]model.RoleDescription, error)
|
||||
List(ctx context.Context, organizationRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error)
|
||||
Roles(ctx context.Context, refs []bson.ObjectID) ([]model.RoleDescription, error)
|
||||
List(ctx context.Context, organizationRef bson.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package storable
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,16 +15,16 @@ const (
|
||||
)
|
||||
|
||||
type Base struct {
|
||||
ID primitive.ObjectID `bson:"_id" json:"id"`
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // Timestamp for when the comment was created
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // Timestamp for when the comment was last updated (optional)
|
||||
ID bson.ObjectID `bson:"_id" json:"id"`
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // Timestamp for when the comment was created
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // Timestamp for when the comment was last updated (optional)
|
||||
}
|
||||
|
||||
func (b *Base) GetID() *primitive.ObjectID {
|
||||
func (b *Base) GetID() *bson.ObjectID {
|
||||
return &b.ID
|
||||
}
|
||||
|
||||
func (b *Base) SetID(objID primitive.ObjectID) {
|
||||
func (b *Base) SetID(objID bson.ObjectID) {
|
||||
b.ID = objID
|
||||
b.CreatedAt = time.Now()
|
||||
b.UpdatedAt = time.Now()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package storable
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
const (
|
||||
RefField = "ref"
|
||||
)
|
||||
|
||||
type Ref struct {
|
||||
Ref primitive.ObjectID `bson:"ref" json:"ref"`
|
||||
Ref bson.ObjectID `bson:"ref" json:"ref"`
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package storable
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Storable interface {
|
||||
GetID() *primitive.ObjectID
|
||||
SetID(objID primitive.ObjectID)
|
||||
GetID() *bson.ObjectID
|
||||
SetID(objID bson.ObjectID)
|
||||
Update()
|
||||
Collection() string
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/repository/builder"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type DB[T storable.Storable] interface {
|
||||
Create(ctx context.Context, object T) error
|
||||
InsertMany(ctx context.Context, objects []T) error
|
||||
Get(ctx context.Context, objectRef primitive.ObjectID, result T) error
|
||||
Get(ctx context.Context, objectRef bson.ObjectID, result T) error
|
||||
Update(ctx context.Context, object T) error
|
||||
Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error
|
||||
Delete(ctx context.Context, objectRef primitive.ObjectID) error
|
||||
Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error
|
||||
Delete(ctx context.Context, objectRef bson.ObjectID) error
|
||||
DeleteMany(ctx context.Context, query builder.Query) error
|
||||
DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error
|
||||
DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error
|
||||
FindOne(ctx context.Context, query builder.Query, result T) error
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
type CascadeDeleterT = func(ctx context.Context, objectRef primitive.ObjectID) error
|
||||
type CascadeDeleterT = func(ctx context.Context, objectRef bson.ObjectID) error
|
||||
|
||||
type DBImp[T storable.Storable] struct {
|
||||
Logger mlogger.Logger
|
||||
@@ -40,7 +40,7 @@ func (db *DBImp[T]) InsertMany(ctx context.Context, objects []T) error {
|
||||
return db.Repository.InsertMany(ctx, storables)
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) Get(ctx context.Context, objectRef primitive.ObjectID, result T) error {
|
||||
func (db *DBImp[T]) Get(ctx context.Context, objectRef bson.ObjectID, result T) error {
|
||||
return db.Repository.Get(ctx, objectRef, result)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (db *DBImp[T]) Update(ctx context.Context, object T) error {
|
||||
return db.Repository.Update(ctx, object)
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error {
|
||||
func (db *DBImp[T]) Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error {
|
||||
return db.Repository.Patch(ctx, objectRef, patch)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (db *DBImp[T]) PatchMany(ctx context.Context, query builder.Query, patch bu
|
||||
return db.Repository.PatchMany(ctx, query, patch)
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) Delete(ctx context.Context, objectRef primitive.ObjectID) error {
|
||||
func (db *DBImp[T]) Delete(ctx context.Context, objectRef bson.ObjectID) error {
|
||||
return db.Repository.Delete(ctx, objectRef)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (db *DBImp[T]) FindOne(ctx context.Context, query builder.Query, result T)
|
||||
return db.Repository.FindOneByFilter(ctx, query, result)
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) {
|
||||
func (db *DBImp[T]) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) {
|
||||
return db.Repository.ListIDs(ctx, query)
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ func (db *DBImp[T]) SetDeleter(deleter CascadeDeleterT) {
|
||||
db.cdeleter = deleter
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) deleteCascadeStub(_ context.Context, objectRef primitive.ObjectID) error {
|
||||
func (db *DBImp[T]) deleteCascadeStub(_ context.Context, objectRef bson.ObjectID) error {
|
||||
db.Logger.Warn("Unimplemented cascade delete call", mzap.ObjRef("object_ref", objectRef))
|
||||
return merrors.NotImplemented("custom implementation required")
|
||||
}
|
||||
|
||||
func (db *DBImp[T]) DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error {
|
||||
func (db *DBImp[T]) DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error {
|
||||
return db.cdeleter(ctx, objectRef)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/tech/sendico/pkg/db/internal/mongo/tseriesimp"
|
||||
tsoptions "github.com/tech/sendico/pkg/db/tseries/options"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
func CreateMongoTimeSeries(ctx context.Context, db *mongo.Database, tsOpts *tsoptions.Options) (TimeSeries, error) {
|
||||
|
||||
Reference in New Issue
Block a user