object

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const PrimarySortKey = "objectId"

Variables

This section is empty.

Functions

func IsObjectSortBy

func IsObjectSortBy(sortBy string) bool

Types

type CreateObjectSpec

type CreateObjectSpec struct {
	ObjectType string                 `json:"objectType" validate:"required,valid_object_type"`
	ObjectId   string                 `json:"objectId"   validate:"omitempty,valid_object_id"`
	Meta       map[string]interface{} `json:"meta"`
}

func (CreateObjectSpec) ToObject

func (spec CreateObjectSpec) ToObject() (*Object, error)

type FilterOptions

type FilterOptions struct {
	ObjectType string `json:"objectType,omitempty"`
}

type ListObjectSpecV1 added in v0.57.0

type ListObjectSpecV1 []ObjectSpec

type ListObjectsSpecV2 added in v0.57.0

type ListObjectsSpecV2 struct {
	Results    []ObjectSpec    `json:"results"`
	NextCursor *service.Cursor `json:"nextCursor,omitempty"`
	PrevCursor *service.Cursor `json:"prevCursor,omitempty"`
}

type Model

type Model interface {
	GetID() int64
	GetObjectType() string
	GetObjectId() string
	GetMeta() *string
	SetMeta(meta map[string]interface{}) error
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time
	GetDeletedAt() *time.Time
	ToObjectSpec() (*ObjectSpec, error)
}

type MySQLRepository

type MySQLRepository struct {
	database.SQLRepository
}

func NewMySQLRepository

func NewMySQLRepository(db *database.MySQL) *MySQLRepository

func (MySQLRepository) BatchGetByObjectTypeAndIds

func (repo MySQLRepository) BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]Model, error)

func (MySQLRepository) Create

func (repo MySQLRepository) Create(ctx context.Context, model Model) (int64, error)

func (MySQLRepository) DeleteByObjectTypeAndId

func (repo MySQLRepository) DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) error

func (MySQLRepository) DeleteWarrantsMatchingObject

func (repo MySQLRepository) DeleteWarrantsMatchingObject(ctx context.Context, objectType string, objectId string) error

func (MySQLRepository) DeleteWarrantsMatchingSubject

func (repo MySQLRepository) DeleteWarrantsMatchingSubject(ctx context.Context, subjectType string, subjectId string) error

func (MySQLRepository) GetById

func (repo MySQLRepository) GetById(ctx context.Context, id int64) (Model, error)

func (MySQLRepository) GetByObjectTypeAndId

func (repo MySQLRepository) GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (Model, error)

func (MySQLRepository) List

func (repo MySQLRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, *service.Cursor, *service.Cursor, error)

func (MySQLRepository) UpdateByObjectTypeAndId

func (repo MySQLRepository) UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, model Model) error

type Object

type Object struct {
	ID         int64      `mysql:"id"         postgres:"id"          sqlite:"id"`
	ObjectType string     `mysql:"objectType" postgres:"object_type" sqlite:"objectType"`
	ObjectId   string     `mysql:"objectId"   postgres:"object_id"   sqlite:"objectId"`
	Meta       *string    `mysql:"meta"       postgres:"meta"        sqlite:"meta"`
	CreatedAt  time.Time  `mysql:"createdAt"  postgres:"created_at"  sqlite:"createdAt"`
	UpdatedAt  time.Time  `mysql:"updatedAt"  postgres:"updated_at"  sqlite:"updatedAt"`
	DeletedAt  *time.Time `mysql:"deletedAt"  postgres:"deleted_at"  sqlite:"deletedAt"`
}

func (Object) GetCreatedAt

func (object Object) GetCreatedAt() time.Time

func (Object) GetDeletedAt

func (object Object) GetDeletedAt() *time.Time

func (Object) GetID

func (object Object) GetID() int64

func (Object) GetMeta

func (object Object) GetMeta() *string

func (Object) GetObjectId

func (object Object) GetObjectId() string

func (Object) GetObjectType

func (object Object) GetObjectType() string

func (Object) GetUpdatedAt

func (object Object) GetUpdatedAt() time.Time

func (*Object) SetMeta

func (object *Object) SetMeta(newMeta map[string]interface{}) error

func (Object) ToObjectSpec

func (object Object) ToObjectSpec() (*ObjectSpec, error)

type ObjectListParamParser

type ObjectListParamParser struct{}

func (ObjectListParamParser) GetDefaultSortBy

func (parser ObjectListParamParser) GetDefaultSortBy() string

func (ObjectListParamParser) GetSupportedSortBys

func (parser ObjectListParamParser) GetSupportedSortBys() []string

func (ObjectListParamParser) ParseValue

func (parser ObjectListParamParser) ParseValue(val string, sortBy string) (interface{}, error)

type ObjectRepository

type ObjectRepository interface {
	Create(ctx context.Context, object Model) (int64, error)
	GetById(ctx context.Context, id int64) (Model, error)
	GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (Model, error)
	BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]Model, error)
	List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, *service.Cursor, *service.Cursor, error)
	UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, object Model) error
	DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) error
	DeleteWarrantsMatchingObject(ctx context.Context, objectType string, objectId string) error
	DeleteWarrantsMatchingSubject(ctx context.Context, subjectType string, subjectId string) error
}

func NewRepository

func NewRepository(db database.Database) (ObjectRepository, error)

type ObjectService

type ObjectService struct {
	service.BaseService
	// contains filtered or unexported fields
}

func NewService

func NewService(env service.Env, repository ObjectRepository) *ObjectService

func (ObjectService) BatchGetByObjectTypeAndIds

func (svc ObjectService) BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]ObjectSpec, error)

func (ObjectService) Create

func (svc ObjectService) Create(ctx context.Context, objectSpec CreateObjectSpec) (*ObjectSpec, error)

func (ObjectService) DeleteByObjectTypeAndId

func (svc ObjectService) DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (*wookie.Token, error)

func (ObjectService) GetByObjectTypeAndId

func (svc ObjectService) GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (*ObjectSpec, error)

func (ObjectService) List

func (svc ObjectService) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]ObjectSpec, *service.Cursor, *service.Cursor, error)

func (ObjectService) Routes

func (svc ObjectService) Routes() ([]service.Route, error)

func (ObjectService) UpdateByObjectTypeAndId

func (svc ObjectService) UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, updateSpec UpdateObjectSpec) (*ObjectSpec, error)

type ObjectSpec

type ObjectSpec struct {
	// NOTE: ID is required here for internal use.
	// However, we don't return it to the client.
	ID         int64                  `json:"-"`
	ObjectType string                 `json:"objectType"`
	ObjectId   string                 `json:"objectId"`
	Meta       map[string]interface{} `json:"meta,omitempty"`
	CreatedAt  time.Time              `json:"createdAt"`
}

type PostgresRepository

type PostgresRepository struct {
	database.SQLRepository
}

func NewPostgresRepository

func NewPostgresRepository(db *database.Postgres) *PostgresRepository

func (PostgresRepository) BatchGetByObjectTypeAndIds

func (repo PostgresRepository) BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]Model, error)

func (PostgresRepository) Create

func (repo PostgresRepository) Create(ctx context.Context, model Model) (int64, error)

func (PostgresRepository) DeleteByObjectTypeAndId

func (repo PostgresRepository) DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) error

func (PostgresRepository) DeleteWarrantsMatchingObject

func (repo PostgresRepository) DeleteWarrantsMatchingObject(ctx context.Context, objectType string, objectId string) error

func (PostgresRepository) DeleteWarrantsMatchingSubject

func (repo PostgresRepository) DeleteWarrantsMatchingSubject(ctx context.Context, subjectType string, subjectId string) error

func (PostgresRepository) GetById

func (repo PostgresRepository) GetById(ctx context.Context, id int64) (Model, error)

func (PostgresRepository) GetByObjectTypeAndId

func (repo PostgresRepository) GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (Model, error)

func (PostgresRepository) List

func (repo PostgresRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, *service.Cursor, *service.Cursor, error)

func (PostgresRepository) UpdateByObjectTypeAndId

func (repo PostgresRepository) UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, model Model) error

type SQLiteRepository

type SQLiteRepository struct {
	database.SQLRepository
}

func NewSQLiteRepository

func NewSQLiteRepository(db *database.SQLite) *SQLiteRepository

func (SQLiteRepository) BatchGetByObjectTypeAndIds

func (repo SQLiteRepository) BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]Model, error)

func (SQLiteRepository) Create

func (repo SQLiteRepository) Create(ctx context.Context, model Model) (int64, error)

func (SQLiteRepository) DeleteByObjectTypeAndId

func (repo SQLiteRepository) DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) error

func (SQLiteRepository) DeleteWarrantsMatchingObject

func (repo SQLiteRepository) DeleteWarrantsMatchingObject(ctx context.Context, objectType string, objectId string) error

func (SQLiteRepository) DeleteWarrantsMatchingSubject

func (repo SQLiteRepository) DeleteWarrantsMatchingSubject(ctx context.Context, subjectType string, subjectId string) error

func (SQLiteRepository) GetById

func (repo SQLiteRepository) GetById(ctx context.Context, id int64) (Model, error)

func (SQLiteRepository) GetByObjectTypeAndId

func (repo SQLiteRepository) GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (Model, error)

func (SQLiteRepository) List

func (repo SQLiteRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, *service.Cursor, *service.Cursor, error)

func (SQLiteRepository) UpdateByObjectTypeAndId

func (repo SQLiteRepository) UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, model Model) error

type Service added in v0.41.0

type Service interface {
	Create(ctx context.Context, objectSpec CreateObjectSpec) (*ObjectSpec, error)
	GetByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (*ObjectSpec, error)
	BatchGetByObjectTypeAndIds(ctx context.Context, objectType string, objectIds []string) ([]ObjectSpec, error)
	List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]ObjectSpec, *service.Cursor, *service.Cursor, error)
	UpdateByObjectTypeAndId(ctx context.Context, objectType string, objectId string, updateSpec UpdateObjectSpec) (*ObjectSpec, error)
	DeleteByObjectTypeAndId(ctx context.Context, objectType string, objectId string) (*wookie.Token, error)
}

type UpdateObjectSpec

type UpdateObjectSpec struct {
	Meta map[string]interface{} `json:"meta"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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