product

package
v0.0.0-...-8fab053 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Collection = "products"
)

Variables

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

	ErrInvalidID = errors.New("invalid id")
)

Functions

This section is empty.

Types

type Dress

type Dress struct {
	ID          primitive.ObjectID   `bson:"_id,omitempty" json:"id"`
	Seller      string               `bson:"seller,omitempty" json:"seller"`
	Title       string               `bson:"title,omitempty" json:"title"`
	Type        TypeEnum             `bson:"type" json:"type"`
	Price       primitive.Decimal128 `bson:"price,omitempty" json:"price"`
	Currency    string               `bson:"currency,omitempty" json:"currency"`
	Description string               `bson:"description,omitempty" json:"description"`
	SKU         string               `bson:"sku,omitempty" json:"sku"`
	Stock       int                  `bson:"stock,omitempty" json:"stock"`
	Sizes       []string             `bson:"sizes,omitempty" json:"sizes"`
	Colors      []string             `bson:"colors,omitempty" json:"colors"`
	CreatedAt   time.Time            `bson:"created_at,omitempty" json:"created_at"`
}

type Food

type Food struct {
	ID          primitive.ObjectID   `bson:"_id,omitempty" json:"id"`
	Seller      string               `bson:"seller,omitempty" json:"seller"`
	Title       string               `bson:"title,omitempty" json:"title"`
	Type        TypeEnum             `bson:"type" json:"type"`
	Price       primitive.Decimal128 `bson:"price,omitempty" json:"price"`
	Currency    string               `bson:"currency,omitempty" json:"currency"`
	Description string               `bson:"description,omitempty" json:"description"`
	SKU         string               `bson:"sku,omitempty" json:"sku"`
	Stock       int                  `bson:"stock,omitempty" json:"stock"`
	ExpireAt    time.Time            `bson:"expire_at,omitempty" json:"expire_at"`
	CreatedAt   time.Time            `bson:"created_at,omitempty" json:"created_at"`
}

type Info

type Info struct {
	ID          primitive.ObjectID   `bson:"_id,omitempty" json:"id"`
	Seller      string               `bson:"seller,omitempty" json:"seller"`
	Title       string               `bson:"title,omitempty" json:"title"`
	Type        TypeEnum             `bson:"type" json:"type"`
	Price       primitive.Decimal128 `bson:"price,omitempty" json:"price"`
	Currency    string               `bson:"currency,omitempty" json:"currency"`
	Description string               `bson:"description,omitempty" json:"description"`
	SKU         string               `bson:"sku,omitempty" json:"sku"`
	Stock       int                  `bson:"stock,omitempty" json:"stock"`
	Sizes       []string             `bson:"sizes,omitempty" json:"sizes"`
	Colors      []string             `bson:"colors,omitempty" json:"colors"`
	License     string               `bson:"license,omitempty" json:"license"`
	Code        string               `bson:"code,omitempty" json:"code"`
	ExpireAt    time.Time            `bson:"expire_at,omitempty" json:"expire_at"`
	CreatedAt   time.Time            `bson:"created_at,omitempty" json:"created_at"`
}

Info represent a individual product information.

type NewDress

type NewDress struct {
	Title       string   `json:"title" validate:"required"`
	Price       string   `json:"price" validate:"required"`
	Currency    string   `json:"currency" validate:"required"`
	Description string   `json:"description"`
	SKU         string   `json:"sku"`
	Stock       int      `json:"stock"`
	Sizes       []string `json:"sizes"`
	Colors      []string `json:"colors"`
}

type NewFood

type NewFood struct {
	Title       string    `json:"title" validate:"required"`
	Price       string    `json:"price" validate:"required"`
	Currency    string    `json:"currency" validate:"required"`
	Description string    `json:"description"`
	SKU         string    `json:"sku"`
	Stock       int       `json:"stock"`
	ExpireAt    time.Time `json:"expire_at"`
}

type NewSoftware

type NewSoftware struct {
	Title       string  `json:"title" validate:"required"`
	Price       float64 `json:"price" validate:"required"`
	Currency    string  `json:"currency" validate:"required"`
	Description string  `json:"description"`
	SKU         string  `json:"sku"`
	Stock       int     `json:"stock"`
	License     string  `json:"license"`
	Code        string  `json:"code"`
}

type Product

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

Product manage set of API's for product access.

func New

func New(log *logrus.Logger, db *mongo.Database) Product

New constructs a product for access api.

func (Product) CreateDress

func (p Product) CreateDress(ctx context.Context, seller string, nd NewDress, date time.Time) (Info, error)

CreateDress inserts a new product dress into the database.

func (Product) CreateFood

func (p Product) CreateFood(ctx context.Context, seller string, nf NewFood, date time.Time) (Info, error)

CreateFood inserts a new product food into the database.

func (Product) CreateSoftware

func (p Product) CreateSoftware(ctx context.Context, seller string, ns NewSoftware, date time.Time) (Info, error)

CreateSoftware inserts a new product software into the database.

func (Product) QueryByID

func (p Product) QueryByID(ctx context.Context, id string) (Info, error)

QueryByID gets a specific product from the database by id.

func (Product) QueryDressByID

func (p Product) QueryDressByID(ctx context.Context, id string) (Dress, error)

func (Product) QueryFoodByID

func (p Product) QueryFoodByID(ctx context.Context, id string) (Food, error)

func (Product) QuerySoftwareByID

func (p Product) QuerySoftwareByID(ctx context.Context, id string) (Software, error)

func (Product) QuerySoftwareByIDs

func (p Product) QuerySoftwareByIDs(ctx context.Context, ids []string) ([]Software, error)

type Software

type Software struct {
	ID          primitive.ObjectID   `bson:"_id,omitempty" json:"id"`
	Seller      string               `bson:"seller,omitempty" json:"seller"`
	Title       string               `bson:"title,omitempty" json:"title"`
	Type        TypeEnum             `bson:"type" json:"type"`
	Price       primitive.Decimal128 `bson:"price,omitempty" json:"price"`
	Currency    string               `bson:"currency,omitempty" json:"currency"`
	Description string               `bson:"description,omitempty" json:"description"`
	SKU         string               `bson:"sku,omitempty" json:"sku"`
	Stock       int                  `bson:"stock,omitempty" json:"stock"`
	License     string               `bson:"license,omitempty" json:"license"`
	Code        string               `bson:"code,omitempty" json:"code"`
	CreatedAt   time.Time            `bson:"created_at,omitempty" json:"created_at"`
}

type TypeEnum

type TypeEnum string
const (
	SoftwareType TypeEnum = "Software"
	FoodType     TypeEnum = "Food"
	DressType    TypeEnum = "Dress"
)

Jump to

Keyboard shortcuts

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