engine

package
v0.0.0-...-40fc3ee Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalogue

type Catalogue interface {
	Insert(ctx context.Context, name, details, description, typ string, products, tags []string) error

	// Update is the update-a-catalogue use-case
	Update(ctx context.Context, id, name, details, description, typ string, products, tags []string) error

	// Query is the list-the-catalogues use-case
	Query(ctx context.Context, skip uint64, take uint64) ([]domain.Catalogue, error)

	// FindOne ...
	FindOne(ctx context.Context, id string) (*domain.Catalogue, error)

	// RemoveDelete ...
	Remove(ctx context.Context, id string) (string, error)

	// ListAllCatalogues ...
	ListAllCatalogues(ctx context.Context, skip, take uint64) (*[]domain.Catalogue, error)
}

Catalogue ...

type CatalogueRepository

type CatalogueRepository interface {

	// Catalogue adds a new Catalogue to the datastore
	Insert(c context.Context, catalogue domain.Catalogue) error

	// Put adds a new Catalogue to the datastore
	Update(c context.Context, catalogue domain.Catalogue, id string) error

	// Query returns existing catalogues matching the
	// query provided
	Query(c context.Context, query *Query) []*domain.Catalogue

	// FindOne returns ...
	FindOne(c context.Context, id string) (*domain.Catalogue, error)

	// Remove ...
	Remove(c context.Context, id string) (string, error)

	// ListAllCatalogues ...
	ListAllCatalogues(ctx context.Context, skip uint64, take uint64) ([]domain.Catalogue, error)
}

CatalogueRepository defines the methods that any data storage provider needs to implement to get and store catalogues

type Condition

type Condition byte

Condition represents a filter comparison operation between a field and a value

const (
	// Equal if it should be the same
	Equal Condition = 1 << iota

	// LessThan if it should be smaller
	LessThan

	// LessThanOrEqual if it should be smaller or equal
	LessThanOrEqual

	// GreaterThan if it should be larger
	GreaterThan

	// GreaterThanOrEqual if it should be equal or greater than
	GreaterThanOrEqual
)

type Direction

type Direction byte

Direction represents a query sort direction

const (
	// Ascending means going up, A-Z
	Ascending Direction = 1 << iota

	// Descending means reverse order, Z-A
	Descending
)

type Factory

type Factory interface {
	// NewCatalogue creates a new Catalogue interactor
	NewCatalogue() Catalogue
}

Factory interface allows us to provide other parts of the system with a way to make instances of our use-case / interactors when they need to

func NewEngine

func NewEngine(s StorageFactory) Factory

NewEngine creates a new engine factory that will make use of the passed in StorageFactory for any data persistence needs.

type Filter

type Filter struct {
	Property  string
	Condition Condition
	Value     interface{}
}

Filter represents a filter operation on a single field

func NewFilter

func NewFilter(property string, condition Condition, value interface{}) *Filter

NewFilter creates a new property filter

type JWTSignParser

type JWTSignParser interface {
	Sign(claims map[string]interface{}, secret string) (map[string]interface{}, error)
	Parse(tokenStr string, secret string) (map[string]interface{}, error)
}

JWTSignParser ...

type Order

type Order struct {
	Property  string
	Direction Direction
}

Order represents a sort operation on a single field

func NewOrder

func NewOrder(property string, direction Direction) *Order

NewOrder creates a new query order

type Product

type Product interface {
	InsertProduct(ctx context.Context, name, details, description, typ string, tags []string, price float64, discount float32) error

	// Update is the update-a-catalogue use-case
	UpdateProduct(ctx context.Context, id, name, details, description, typ string, tags []string, price float64, discount float32) error

	// Query is the list-the-catalogues use-case
	QueryProduct(ctx context.Context, skip uint64, take uint64) ([]domain.Product, error)

	// FindOne ...
	FindOneProduct(ctx context.Context, id string) (*domain.Product, error)

	// RemoveDelete ...
	RemoveProduct(ctx context.Context, id string) (string, error)

	// ListAllProducts ...
	ListAllProducts(ctx context.Context, skip, take uint64) (*[]domain.Product, error)
}

Product ...

type ProductRepository

type ProductRepository interface {

	// Product adds a new Product to the datastore
	Insert(c context.Context, product domain.Product) error

	// Put adds a new Product to the datastore
	Update(c context.Context, product domain.Product, id string) error

	// Query returns existing products matching the
	// query provided
	Query(c context.Context, query *Query) []*domain.Product

	// FindOne returns ...
	FindOne(c context.Context, id string) (*domain.Product, error)

	// Remove ...
	Remove(c context.Context, id string) (string, error)

	// ListAllProducts ...
	ListAllProducts(ctx context.Context, skip uint64, take uint64) ([]domain.Product, error)
}

ProductRepository defines the methods that any data storage provider needs to implement to get and store product

type Query

type Query struct {
	Name    string
	Offset  int
	Limit   int
	Filters []*Filter
	Orders  []*Order
}

Query represents a query specification for filtering sorting, paging and limiting the data requested

func NewQuery

func NewQuery(name string) *Query

NewQuery creates a new database query spec. The name is what the storage system should use to identify the types, usually a table or collection name.

func (*Query) Filter

func (q *Query) Filter(property string, condition Condition, value interface{}) *Query

Filter adds a filter to the query

func (*Query) Order

func (q *Query) Order(property string, direction Direction) *Query

Order adds a sort order to the query

func (*Query) Slice

func (q *Query) Slice(offset, limit int) *Query

Slice adds a slice operation to the query

type QueryBuilder

type QueryBuilder interface {
	Filter(property string, value interface{}) QueryBuilder
	Order(property string, direction Direction)
}

QueryBuilder helps with query creation

type SecurityFactory

type SecurityFactory interface {
	// NewSecurityFactory ...
	NewSecurityFactory() JWTSignParser
}

SecurityFactory ...

type StorageFactory

type StorageFactory interface {
	// NewCatalogueRepository returns a storage specific
	// CatalogueRepository implementation
	NewCatalogueRepository() CatalogueRepository

	// NewProductRepository returns a storage specific
	// ProductRepository implementation
	NewProductRepository() ProductRepository

	Close()
}

StorageFactory is the interface that a storage provider needs to implement so that the engine can request repository instances as it needs them

Jump to

Keyboard shortcuts

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