ddd

package
v0.0.0-...-087ca59 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SoftDeleteFieldName = "isDeleted"
View Source
const TenantIdDbKey = "tenantId"

Variables

View Source
var (
	ErrEntityNotFound = errors.New("entity not found")
)

Functions

func SetAudited

func SetAudited[TKey comparable](ctx context.Context, e any)

func SetAuditedMany

func SetAuditedMany[T any, TKey comparable](ctx context.Context, data []T) []any

SetAuditedMany is a helper function to set audit fields for a slice of pointers. T is not struct ptr

func SetAuditedManyPtr

func SetAuditedManyPtr[T any, TKey comparable](ctx context.Context, data []*T) []any

SetAuditedManyPtr is a helper function to set audit fields for a slice of pointers. T is struct ptr

func WithHardDelete

func WithHardDelete(ctx context.Context) context.Context

Types

type AuditEntityBase

type AuditEntityBase[TKey comparable] struct {
	EntityBase[TKey] `bson:",inline"`
	CreatorId        TKey      `bson:"creatorId"`
	CreatedAt        time.Time `bson:"createdAt"`
}

func (*AuditEntityBase[TKey]) Creating

func (e *AuditEntityBase[TKey]) Creating(ctx context.Context)

type CheckFieldReason

type CheckFieldReason string
const (
	// ReasonOk is used when the value is ok
	ReasonOk CheckFieldReason = "ok"
	// ReasonExistedValue is used when the value is existed
	ReasonExistedValue CheckFieldReason = "value_existed"
	// ReasonRequired is used when the field is required
	ReasonRequired CheckFieldReason = "required"
	// ReasonInvalidField is used when the field is not valid
	ReasonInvalidField CheckFieldReason = "invalid_field"
	// ReasonNotSupport is used when the field is not supported
	ReasonNotSupport CheckFieldReason = "not_support"
)

type CheckFieldResult

type CheckFieldResult struct {
	Result  CheckFieldReason `json:"reason"`
	Message string           `json:"message"`
}

func CheckFieldOk

func CheckFieldOk() *CheckFieldResult

type CreationAuditedEntity

type CreationAuditedEntity[TKey comparable] interface {
	Creating(ctx context.Context)
}

type Entity

type Entity[TKey comparable] interface {
	GetId() TKey
	SetId(id TKey)
}

type EntityBase

type EntityBase[TKey comparable] struct {
	ID TKey `bson:"_id,omitempty"`
}

func (*EntityBase[TKey]) GetId

func (e *EntityBase[TKey]) GetId() TKey

func (*EntityBase[TKey]) SetId

func (e *EntityBase[TKey]) SetId(id TKey)

type FullAuditEntityBase

type FullAuditEntityBase[TKey comparable] struct {
	AuditEntityBase[TKey] `bson:",inline"`
	UpdatedAt             time.Time `bson:"updatedAt,omitempty"`
	UpdaterId             TKey      `bson:"updaterId,omitempty"`
}

func (*FullAuditEntityBase[TKey]) Updating

func (e *FullAuditEntityBase[TKey]) Updating(ctx context.Context)

type IMultiTenancy

type IMultiTenancy interface {
	GetTenant() string
	SetTenant(tenantId string)
}

type ISoftDeleteEntity

type ISoftDeleteEntity[TKey comparable] interface {
	Entity[TKey]
	Deleting(ctx context.Context)
}

type MultiTenantEntity

type MultiTenantEntity struct {
	TenantId string `bson:"tenantId"`
}

func (*MultiTenantEntity) GetTenant

func (m *MultiTenantEntity) GetTenant() string

func (*MultiTenantEntity) SetTenant

func (m *MultiTenantEntity) SetTenant(tenantId string)

type OrderEntity

type OrderEntity interface {
	GetOrder() float64
}

type OrderEntityBase

type OrderEntityBase struct {
	Order float64 `bson:"order"`
}

func (OrderEntityBase) GetOrder

func (e OrderEntityBase) GetOrder() float64

type PagedItems

type PagedItems[T any] struct {
	Items   []T  `json:"items"`
	HasNext bool `json:"hasNext"`
}

func NewPagedItems

func NewPagedItems[T any](items []T, hasNext bool) PagedItems[T]

type RepositoryBase

type RepositoryBase[TEntity any, TKey comparable] interface {
	GetPagedList(ctx context.Context, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)
	GetById(ctx context.Context, id TKey) (*TEntity, error)
	GetOrNilById(ctx context.Context, id TKey) (*TEntity, error)
	GetMany(ctx context.Context, ids []TKey) ([]*TEntity, error)
	Exists(ctx context.Context, id TKey) (bool, error)
	Count(ctx context.Context) (int64, error)
	FindByRegex(ctx context.Context, field, regex string, p *x.PageAndSort) (*x.PagedResult[*TEntity], error)

	Insert(ctx context.Context, entity *TEntity) (*TEntity, error)
	// InsertMany ignoreErr 是否忽略批量插入时的错误, 一般为false, 当导入时忽略重复key的时候可以设为true
	InsertMany(ctx context.Context, entities []*TEntity, ignoreErr bool) ([]*TEntity, error)

	UpdateById(ctx context.Context, id TKey, data *TEntity) (int, error)

	Delete(ctx context.Context, id TKey) (int, error)
	DeleteMany(ctx context.Context, ids []TKey) (int, error)
}

type SoftDeleteEntity

type SoftDeleteEntity[TKey comparable] struct {
	IsDeleted  bool      `bson:"isDeleted"`
	DeletionAt time.Time `bson:"deletedAt,omitempty"`
	DeleterId  TKey      `bson:"deleterId,omitempty"`
}

func (*SoftDeleteEntity[TKey]) Deleting

func (e *SoftDeleteEntity[TKey]) Deleting(ctx context.Context)

type UpdationAuditedEntity

type UpdationAuditedEntity[TKey comparable] interface {
	Updating(ctx context.Context)
}

type WithExtraArrayEntity

type WithExtraArrayEntity[TKey comparable] struct {
	Data []string `bson:"data,omitempty"`
}

func (*WithExtraArrayEntity[TKey]) Append

func (a *WithExtraArrayEntity[TKey]) Append(str string)

type WithExtraEntity

type WithExtraEntity[TKey comparable] struct {
	Extra map[string]string `bson:"extra,omitempty"`
}

func (*WithExtraEntity[TKey]) GetFloat32

func (m *WithExtraEntity[TKey]) GetFloat32(key string) float32

func (*WithExtraEntity[TKey]) GetInt

func (m *WithExtraEntity[TKey]) GetInt(key string) int

func (*WithExtraEntity[TKey]) GetString

func (m *WithExtraEntity[TKey]) GetString(key string) string

func (*WithExtraEntity[TKey]) GetValue

func (m *WithExtraEntity[TKey]) GetValue(key string, v interface{}) (bool, error)

func (*WithExtraEntity[TKey]) SetFloat32

func (m *WithExtraEntity[TKey]) SetFloat32(key string, value float32)

func (*WithExtraEntity[TKey]) SetInt

func (m *WithExtraEntity[TKey]) SetInt(key string, value int)

func (*WithExtraEntity[TKey]) SetString

func (m *WithExtraEntity[TKey]) SetString(key string, value string)

func (*WithExtraEntity[TKey]) SetValue

func (m *WithExtraEntity[TKey]) SetValue(key string, v interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL