models

package
v1.4.5-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 6 Imported by: 36

Documentation

Overview

Package models represents abstraction of business layer object and basic access interfaces for it

Index

Constants

View Source
const (
	ConstErrorModule = "models"
	ConstErrorLevel  = env.ConstErrorLevelModel

	ConstCollectionListLimit = 20
)

Package global constants

Variables

View Source
var (
	ConstStatesList = map[string]string{
		"":   "No state",
		"AL": "Alabama",
		"AK": "Alaska",
		"AZ": "Arizona",
		"AR": "Arkansas",
		"CA": "California",
		"CO": "Colorado",
		"CT": "Connecticut",
		"DC": "District of Columbia",
		"DE": "Delaware",
		"FL": "Florida",
		"GA": "Georgia",
		"GU": "Guam",
		"HI": "Hawaii",
		"ID": "Idaho",
		"IL": "Illinois",
		"IN": "Indiana",
		"IA": "Iowa",
		"KS": "Kansas",
		"KY": "Kentucky",
		"LA": "Louisiana",
		"ME": "Maine",
		"MD": "Maryland",
		"MA": "Massachusetts",
		"MI": "Michigan",
		"MN": "Minnesota",
		"MS": "Mississippi",
		"MO": "Missouri",
		"MT": "Montana",
		"NE": "Nebraska",
		"NV": "Nevada",
		"NH": "New Hampshire",
		"NJ": "New Jersey",
		"NM": "New Mexico",
		"NY": "New York",
		"NC": "North Carolina",
		"ND": "North Dakota",
		"OH": "Ohio",
		"OK": "Oklahoma",
		"OR": "Oregon",
		"PA": "Pennsylvania",
		"PR": "Puerto Rico",
		"RI": "Rhode Island",
		"SC": "South Carolina",
		"SD": "South Dakota",
		"TN": "Tennessee",
		"TX": "Texas",
		"UT": "Utah",
		"VT": "Vermont",
		"VA": "Virginia",
		"WA": "Washington",
		"WV": "West Virginia",
		"WI": "Wisconsin",
		"WY": "Wyoming",
	}

	ConstCountriesList = map[string]string{}/* 246 elements not displayed */

	ConstTimeZonesList = map[string]string{
		"UTC":       "(UTC+00:00) Greenwich Mean Time",
		"UTC+01:00": "(UTC+01:00), BST, IST, WEST, CET",
		"UTC+02:00": "(UTC+02:00), CEST, EET",
		"UTC+03:00": "(UTC+03:00), EEST, MSK",
		"UTC+04:00": "(UTC+04:00), MSD",
		"UTC+08:00": "(UTC+08:00), AWST, WST",
		"UTC+09:30": "(UTC+09:30), ACST, CST",
		"UTC+10:00": "(UTC+10:00), AEST",
		"UTC+10:30": "(UTC+10:30), ACDT",
		"UTC+11:00": "(UTC+11:00), AEDT",
		"UTC-03:00": "(UTC-03:00), ADT",
		"UTC-04:00": "(UTC-04:00), AST, AST, EDT",
		"UTC-05:00": "(UTC-05:00), EST, CDT",
		"UTC-06:00": "(UTC-06:00), CST, MDT",
		"UTC-07:00": "(UTC-07:00), MST, PDT",
		"UTC-08:00": "(UTC-08:00), PST, AKDT",
		"UTC-09:00": "(UTC-09:00), AKST",
		"UTC-10:00": "(UTC-10:00), HST",
	}
)

Package global variables

Functions

func ApplyExtraAttributes

func ApplyExtraAttributes(context api.InterfaceApplicationContext, collection InterfaceCollection) error

ApplyExtraAttributes modifies given model collection with adding extra attributes to list

  • default attributes are specified in StructListItem as static fields
  • StructListItem fields can be not a direct copy of model attribute,
  • extra attributes are taken from model directly

func ApplyFilters

func ApplyFilters(context api.InterfaceApplicationContext, collection db.InterfaceDBCollection) error

ApplyFilters modifies collection with applying filters from request URL

func GetDeclaredModels

func GetDeclaredModels() map[string]InterfaceModel

GetDeclaredModels returns all currently registered in system models

func GetListLimit

func GetListLimit(context api.InterfaceApplicationContext) (int, int)

GetListLimit returns (offset, limit, error) values based on request string value

"1,2" will return offset: 1, limit: 2, error: nil
"2" will return offset: 0, limit: 2, error: nil
"something wrong" will return offset: 0, limit: 0, error: [error msg]

func RegisterModel

func RegisterModel(ModelName string, Model InterfaceModel) error

RegisterModel registers new model to system

func UnRegisterModel

func UnRegisterModel(ModelName string) error

UnRegisterModel removes registered model from system

Types

type InterfaceAttributesDelegate

type InterfaceAttributesDelegate interface {
	New(instance interface{}) (InterfaceAttributesDelegate, error)

	Get(attribute string) interface{}
	Set(attribute string, value interface{}) error
	GetAttributesInfo() []StructAttributeInfo
}

InterfaceAttributesDelegate is a minimal interface for object attribute delegate

type InterfaceCollection

type InterfaceCollection interface {
	GetDBCollection() db.InterfaceDBCollection

	List() ([]StructListItem, error)

	ListAddExtraAttribute(attribute string) error

	ListFilterAdd(attribute string, operator string, value interface{}) error
	ListFilterReset() error

	ListLimit(offset int, limit int) error
}

InterfaceCollection represents interface to access business layer implementation collection

type InterfaceCustomAttributes

type InterfaceCustomAttributes interface {
	GetCustomAttributeCollectionName() string

	AddNewAttribute(newAttribute StructAttributeInfo) error
	RemoveAttribute(attributeName string) error
	EditAttribute(attributeName string, attributeValues StructAttributeInfo) error
}

InterfaceCustomAttributes represents interface to access business layer implementation object custom attributes

type InterfaceExternalAttributes

type InterfaceExternalAttributes interface {
	AddExternalAttributes(delegate InterfaceAttributesDelegate) error
	RemoveExternalAttributes(delegate InterfaceAttributesDelegate) error
	ListExternalAttributes() map[string]InterfaceAttributesDelegate
}

InterfaceExternalAttributes represents interface to access business layer implementation object external attributes

type InterfaceListable

type InterfaceListable interface {
	GetCollection() InterfaceCollection
}

InterfaceListable represents interface to access business layer implementation collection via object instance

type InterfaceMedia

type InterfaceMedia interface {
	AddMedia(mediaType string, mediaName string, content []byte) error
	RemoveMedia(mediaType string, mediaName string) error

	ListMedia(mediaType string) ([]string, error)

	GetMedia(mediaType string, mediaName string) ([]byte, error)
	GetMediaPath(mediaType string) (string, error)
}

InterfaceMedia represents interface to access business layer implementation object assigned media resources

type InterfaceModel

type InterfaceModel interface {
	GetModelName() string
	GetImplementationName() string
	New() (InterfaceModel, error)
}

InterfaceModel represents interface for basic business layer implementation object

func GetModel

func GetModel(ModelName string) (InterfaceModel, error)

GetModel returns registered in system model

type InterfaceObject

type InterfaceObject interface {
	Get(attribute string) interface{}
	Set(attribute string, value interface{}) error

	FromHashMap(hashMap map[string]interface{}) error
	ToHashMap() map[string]interface{}

	GetAttributesInfo() []StructAttributeInfo
}

InterfaceObject represents interface to access business layer implementation object via get/set functions

type InterfaceStorable

type InterfaceStorable interface {
	GetID() string
	SetID(string) error

	Save() error
	Load(id string) error
	Delete() error
}

InterfaceStorable represents interface load/store business layer implementation object from database

func GetModelAndSetID

func GetModelAndSetID(modelName string, modelID string) (InterfaceStorable, error)

GetModelAndSetID retrieves current model implementation and sets its ID to some value

func LoadModelByID

func LoadModelByID(modelName string, modelID string) (InterfaceStorable, error)

LoadModelByID loads model data in current implementation

type StructAttributeInfo

type StructAttributeInfo struct {
	Model      string
	Collection string
	Attribute  string
	Type       string
	Label      string
	IsRequired bool
	IsStatic   bool
	Group      string
	Editors    string
	Options    string
	Default    string
	Validators string
	IsLayered  bool
	IsPublic   bool
}

StructAttributeInfo represents type to hold business layer object attribute information

type StructListItem

type StructListItem struct {
	ID    string
	Name  string
	Image string
	Desc  string

	Extra map[string]interface{}
}

StructListItem represents type to hold business layer object information within collection

Directories

Path Synopsis
blog
post
Package post represents abstraction of business layer blog post object
Package post represents abstraction of business layer blog post object
Package cart represents abstraction of business layer cart object
Package cart represents abstraction of business layer cart object
Package category represents abstraction of business layer category object
Package category represents abstraction of business layer category object
Package checkout represents abstraction of business layer checkout object
Package checkout represents abstraction of business layer checkout object
Package cms represents abstraction of business layer cms page and cms block objects
Package cms represents abstraction of business layer cms page and cms block objects
discount
Package order represents abstraction of business layer purchase order object
Package order represents abstraction of business layer purchase order object
Package product represents abstraction of business layer product object
Package product represents abstraction of business layer product object
Package product represents abstraction of business layer product object
Package product represents abstraction of business layer product object
Package subscription represents abstraction of business layer purchase subscription object
Package subscription represents abstraction of business layer purchase subscription object
Package visitor represents abstraction of business layer visitor object
Package visitor represents abstraction of business layer visitor object

Jump to

Keyboard shortcuts

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