store

package
v0.0.0-...-93fa5b8 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound not found.
	ErrNotFound = errors.New("not found")
	// ErrInvalidInput invalid input.
	ErrInvalidInput = errors.New("invalid input")
	// ErrNoResults no results.
	ErrNoResults = errors.New("no results")
	// ErrNilPointer nil pointer passed.
	ErrNilPointer = errors.New("nil pointer passed")
)
View Source
var NilID = ID(0)
View Source
var (
	// StorageURL default storage engine.
	StorageURL string
)

Functions

func ImagePath

func ImagePath(itemID *ID, imageID *uuid.UUID, filename string) string

func Register

func Register(name string, driver Driver)

Register globally registers a driver.

func Slugify

func Slugify(str string) string

func SortBidsByCreatedAtAsc

func SortBidsByCreatedAtAsc(b1, b2 *Bid) bool

func SortBidsByCreatedAtDesc

func SortBidsByCreatedAtDesc(b1, b2 *Bid) bool

func SortBidsByIDAsc

func SortBidsByIDAsc(b1, b2 *Bid) bool

func SortBidsByIDDesc

func SortBidsByIDDesc(b1, b2 *Bid) bool

func SortItemsByCreatedAtAsc

func SortItemsByCreatedAtAsc(i1, i2 *Item) bool

func SortItemsByCreatedAtDesc

func SortItemsByCreatedAtDesc(i1, i2 *Item) bool

func SortItemsByIDAsc

func SortItemsByIDAsc(i1, i2 *Item) bool

func SortItemsByIDDesc

func SortItemsByIDDesc(i1, i2 *Item) bool

Types

type Bid

type Bid struct {
	ID        ID         `json:"id" db:"id"`
	CreatedAt *time.Time `json:"created_at" db:"created_at"`
	Value     Currency   `json:"value" db:"value"`
	UserID    *ID        `json:"user_id" db:"user_id"`
	ItemID    *ID        `json:"item_id" db:"item_id"`
	Valid     bool       `json:"valid" db:"valid"`
	User      *User      `json:"-"`
	Item      *Item      `json:"-"`
}

type BidSorter

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

func BidsOrderedBy

func BidsOrderedBy(less ...bidLess) *BidSorter

func (*BidSorter) Len

func (bs *BidSorter) Len() int

func (*BidSorter) Less

func (bs *BidSorter) Less(i, j int) bool

func (*BidSorter) Sort

func (bs *BidSorter) Sort(bids []*Bid)

func (*BidSorter) Swap

func (bs *BidSorter) Swap(i, j int)

type Bids

type Bids []*Bid

func (*Bids) FilterValid

func (b *Bids) FilterValid() *Bids

type Currency

type Currency int64

func (Currency) String

func (c Currency) String() string

type Driver

type Driver interface {
	// Open creates a connection to the driver.
	Open(url string) (Driver, error)
	// Close closes the driver connection.
	Close() error
	// CreateItem creates a new item.
	CreateItem(item *Item) error
	// ItemCount get count of items.
	ItemCount(addInactive bool) int
	// GetBySlug returns an item by its unique slug.
	GetBySlug(slug string) (*Item, error)
	// ListItems returns a list of items.
	ListItems(opts *PaginateOptions, addInactive bool) ([]*Item, error)
	// ItemBids gets a list of bids for an item.
	ItemBids(itemID *ID, opts *PaginateOptions) ([]*Bid, error)
	// CoverImage returns the lowest-order image of an item.
	CoverImage(itemID *ID) ([]*Image, error)
	// ItemImages returns the images belonging to an item.
	ItemImages(itemID *ID) ([]*Image, error)
	// GetByID returns an Item by id.
	// GetByID(id *uuid.UUID) (*Item, error)
	//	// DeleteItem deletes an Item by ID.
	//	DeleteItem(id *uuid.UUID) error
	//
	//	// PlaceBid places a bid on item.
	//	PlaceBid(item *Item, bid *Bid) error
	//	// InvalidateBid invalidates a bid.
	//	InvalidateBid(bid *Bid) error
	// AddImages adds an image to the item.
	AddImages(item *Item, image ...IImage) error
	// RemoveImage removes an image to the item.
	RemoveImage(id uuid.UUID) error
}

Driver all storage engines need to implement this interface.

func Open

func Open(url string) (Driver, error)

Open returns a new driver instance.

type ID

type ID uint64

func Must

func Must(i ID, err error) ID

func NewID

func NewID(i interface{}) (ID, error)

func (ID) String

func (id ID) String() string

type IImage

type IImage interface {
	Data() io.Reader
	Obj() *Image
}

type Image

type Image struct {
	ID uuid.UUID
	// Path relative path to asset on fileserver.
	Path string `json:"path" db:"path"`
	// AbsPath absolute path to image.
	AbsPath string `json:"abs_path" db:"abs_path"`
	// OriginalFilename the image's original filename.
	OriginalFilename string
	AltText          string
	CreatedAt        *time.Time `json:"created_at" db:"created_at"`
	UpdatedAt        *time.Time `json:"updated_at" db:"updated_at"`
	ItemID           *ID        `json:"item_id" db:"item_id"`
	Order            uint8      `json:"order" db:"order"`
}

Image retains image properties to save in the filesystem.

type Item

type Item struct {
	ID          ID             `json:"id" db:"id"`
	OwnerID     *ID            `json:"owner_id" db:"owner_id"`
	Name        string         `json:"name" db:"name"`
	Slug        string         `json:"slug" db:"slug"`
	Description string         `json:"description" db:"description"`
	MinBid      Currency       `json:"min_bid" db:"min_bid"`
	MaxBid      Currency       `json:"max_bid" db:"max_bid"`
	BidInterval *time.Duration `json:"bid_interval" db:"bid_interval"`
	BidDeadline *time.Time     `json:"bid_deadline" db:"bid_deadline"`
	Bids        Bids           `json:"bids"`
	BidsPublic  bool           `json:"bids_public" db:"bids_public"`
	CreatedAt   *time.Time     `json:"created_at" db:"created_at"`
	UpdatedAt   *time.Time     `json:"updated_at" db:"updated_at"`
	PublishedAt *time.Time     `json:"published_at" db:"published_at"`
	Images      []*Image       `json:"images"`
	Owner       *User          `json:"-"`
}

Item struct holds an item's data. Note that amounts that refer to currency are unsigned integers * 100 (to retain decimal precision).

func (*Item) HighestBid

func (i *Item) HighestBid() *Bid

MaxBid returns the higuest bid of an Item.

type ItemSorter

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

func ItemsOrderedBy

func ItemsOrderedBy(less ...itemLess) *ItemSorter

func (*ItemSorter) Len

func (is *ItemSorter) Len() int

func (*ItemSorter) Less

func (is *ItemSorter) Less(i, j int) bool

func (*ItemSorter) Sort

func (is *ItemSorter) Sort(items []*Item)

func (*ItemSorter) Swap

func (is *ItemSorter) Swap(i, j int)

type PaginateOptions

type PaginateOptions struct {
	//	LastID      *ID
	//	LastCreated *time.Time
	Limit       int
	Offset      int
	CurrentPage int
}

type User

type User struct {
	ID        ID         `json:"id" db:"id"`
	Username  string     `json:"username" db:"username"`
	CreatedAt *time.Time `json:"created_at" db:"created_at"`
	UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
}

Directories

Path Synopsis
data
Package data has some utilities to instantiate data for tests.
Package data has some utilities to instantiate data for tests.

Jump to

Keyboard shortcuts

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