entities

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

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, err error) error

NewError returns a new GoComError

Types

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) Validate

func (c *Category) Validate() error

Validate validates the category data

type GoComError

type GoComError struct {
	// HTTP status code
	Status int

	// Original error
	Err error
}

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 = uuid.UUID

ID entity ID

func NewID

func NewID() ID

NewID create a new entity ID

func StringToID

func StringToID(s string) (ID, error)

StringToID convert a string to an entity ID

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) Validate

func (m *Manufacturer) Validate() error

Validate 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 int

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

Product data

func (*Product) Validate

func (c *Product) Validate() error

Validate 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