entities

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ContentTypeHTML = "HTML"
View Source
const ContentTypeSimple = "SIMPLE"
View Source
const ProductStatusArchived = "ARCHIVED"
View Source
const ProductStatusAvailable = "AVAILABLE"

Variables

View Source
var ErrInvalidEntity = errors.New("invalid entity")

ErrInvalidEntity indicates the provided entity is invalid

View Source
var ErrInvalidID = errors.New("invalid id")

ErrInvalidID indicates the provided id is malformed

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

ErrNotFound indicates the requested entity is not found

Functions

func NewError

func NewError(status int, code openapi.GocomErrorCode, instance string, err error) error

NewError returns a new GoComError

Types

type AmountInCents added in v0.5.0

type AmountInCents struct {
	// contains filtered or unexported fields
}

func NewAmountInCents added in v0.5.0

func NewAmountInCents(amountInCents int) AmountInCents

func NewAmountInCentsFromString added in v0.5.0

func NewAmountInCentsFromString(amount string) (AmountInCents, error)

NewAmountInCentsFromString converts a decimal string into an AmountInCents, without using float conversions

func (AmountInCents) Int added in v0.5.0

func (a AmountInCents) Int() int

func (AmountInCents) String added in v0.5.0

func (a AmountInCents) String() string

FormatPrice formats a price in cents into a decimal string, without using float conversions.

type Category

type Category struct {
	ID          ID
	Name        string
	Description string

	// ID of the parent.
	// uuid.Nil means it's a root category
	ParentID ID

	// Order (priority) of the category.
	// 1 = highest, inf = lowest
	Order int

	ProductIDs []ID

	Image *Image
}

Category data

func (*Category) Clean added in v0.5.0

func (c *Category) Clean()

func (*Category) Validate

func (c *Category) Validate() error

Validate cleans and validates the category data

type Content added in v0.3.0

type Content struct {
	Name        string
	ContentType ContentType
	Body        string
}

Content data

func (*Content) Validate added in v0.3.0

func (c *Content) Validate() error

Validate validates the content data

type ContentType added in v0.3.0

type ContentType string

func (ContentType) IsValid added in v0.3.0

func (contentType ContentType) IsValid() bool

func (ContentType) String added in v0.3.0

func (contentType ContentType) String() string

type Event added in v0.3.0

type Event struct {
	ID          ID
	Name        string
	Description string
	EventType   string
	Start       time.Time
	End         time.Time
	WholeDay    bool
}

Event data

func (*Event) Clean added in v0.5.0

func (e *Event) Clean()

func (*Event) Validate added in v0.3.0

func (e *Event) Validate() error

Validate cleans and validates the event data

type GoComError

type GoComError struct {
	// HTTP status code
	Status int `json:"status"`

	// Original error
	Err error `json:"-"`

	// Error code
	Code string `json:"code"`

	// Human-readable description of the error
	Message string `json:"message"`

	// Optional - On which object to error occurred
	Instance string `json:"instance"`
}

GoComError allows to bundle a status with the original error. This allows to fine-grained response codes at the API level.

func (*GoComError) Error

func (e *GoComError) Error() string

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID contains an entity ID, which is a valid UUID. ID type is created to make it library agnostic and to add useful helpers like IsNil.

func NewID

func NewID() ID

NewID create a new entity ID

func NewIDFromBytes added in v0.5.0

func NewIDFromBytes(b []byte) (ID, error)

NewIDFromString convert a bytes slice to an entity ID

func NewIDFromString added in v0.5.0

func NewIDFromString(s string) (ID, error)

NewIDFromString convert a string to an entity ID

func NewNilID added in v0.5.0

func NewNilID() ID

NewNilID create a new entity ID with value Nil

func (ID) Bytes added in v0.5.0

func (id ID) Bytes() []byte

Bytes converts the ID to a byte slice. Returns an empty slice in case the ID is Nil.

func (ID) IsNil added in v0.5.0

func (id ID) IsNil() bool

func (ID) String added in v0.5.0

func (id ID) String() string

String converts the ID to a string. Returns an empty string in case the ID is Nil.

type Image

type Image struct {
	ID        ID
	Extension string // File extension
	URLs      map[string]string
	Order     int
}

func (*Image) SetURLsFromConfigs

func (img *Image) SetURLsFromConfigs(service imageproxy.Service, configs map[string]imageproxy.ImageConfig) error

SetURLsFromConfigs generates and sets an URL from the provided config

func (*Image) Validate

func (img *Image) Validate() error

Validate validates the product data

type Manufacturer

type Manufacturer struct {
	ID         ID
	Name       string
	WebsiteURL string
	Image      *Image
}

Manufacturer data

func (*Manufacturer) Clean added in v0.5.0

func (m *Manufacturer) Clean()

func (*Manufacturer) Validate

func (m *Manufacturer) Validate() error

Validate cleans and validates the manufacturer data

type Product

type Product struct {
	ID               ID
	CreatedAt        time.Time
	UpdatedAt        time.Time
	Name             string
	DescriptionShort string
	DescriptionLong  string

	// Price of a single product in cents (1/100)
	Price AmountInCents

	CategoryIDs    []ID
	ManufacturerID ID
	Status         ProductStatus
	StockCount     int
	Images         []*Image
}

Product data

func (*Product) Clean added in v0.5.0

func (p *Product) Clean()

func (*Product) Validate

func (p *Product) Validate() error

Validate cleans and validates the product data

type ProductStatus

type ProductStatus string

func (ProductStatus) String

func (status ProductStatus) String() string

type ResolvedProduct

type ResolvedProduct struct {
	Product
	Manufacturer *Manufacturer
	Categories   []*Category
}

ResolvedProduct is a product for which related entities are included. This way all information is immediately at hand.

Jump to

Keyboard shortcuts

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