data

package
v0.0.0-...-ff4b850 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProductNotFound = fmt.Errorf("product not found")
View Source
var ProductList = productList

Functions

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

func GetgrpcClient

func GetgrpcClient(s string, l *zap.Logger) *grpc.ClientConn

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON serializes the contents of the collection to JSON

Types

type Product

type Product struct {
	// the id for the product
	//
	// required: false
	// min: 1
	ID string `json:"id,omitempty" bson:"_id,omitempty"`
	// the name for this poduct
	//
	// required: true
	// max length: 255
	Name string `json:"name" bson:"name" validate:"required"`
	// the description for this poduct
	//
	// required: false
	// max length: 10000
	Description string `json:"description" bson:"description,omitempty"`
	// the price for the product
	//
	// required: true
	// min: 0.01
	Price float64 `json:"price" bson:"price" validate:"gt=0"`
	// the SKU for the product
	//
	// required: true
	// pattern: [a-z]+-[a-z]+-[a-z]+
	SKU string `json:"sku" bson:"sku" validate:"required,sku"`
}

Product defines the structure for an API product

type Products

type Products []*Product

Products is a collection of Product

type ProductsDB

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

func GetProductsDB

func GetProductsDB(c protos.CurrencyClient, l *zap.Logger, mc *mongo.Client) *ProductsDB

func (*ProductsDB) AddProduct

func (db *ProductsDB) AddProduct(ctx context.Context, d []interface{}) (*mongo.InsertManyResult, error)

AddProduct adds a new product to the database

func (*ProductsDB) DeleteProduct

func (db *ProductsDB) DeleteProduct(ctx context.Context, id primitive.ObjectID) error

DeleteProduct deletes a product from the database

func (*ProductsDB) DisconnectMongoClient

func (db *ProductsDB) DisconnectMongoClient() error

func (*ProductsDB) GetMongoClient

func (db *ProductsDB) GetMongoClient(m string) (*mongo.Client, error)

func (*ProductsDB) GetMongoCollection

func (db *ProductsDB) GetMongoCollection(dbase string, coll string) error

func (*ProductsDB) GetProductByID

func (db *ProductsDB) GetProductByID(ctx context.Context, id primitive.ObjectID, currency string) (*Product, error)

GetProductByID returns a single product which matches the id from the database. If a product is not found this function returns a ProductNotFound error

func (*ProductsDB) GetProducts

func (db *ProductsDB) GetProducts(ctx context.Context, currency string) (Products, error)

GetProducts returns all products from the database

func (*ProductsDB) MigrateDocs

func (db *ProductsDB) MigrateDocs(ctx context.Context) (*mongo.InsertManyResult, error)

func (*ProductsDB) UpdateProduct

func (db *ProductsDB) UpdateProduct(ctx context.Context, p []*Product, id primitive.ObjectID) (*mongo.BulkWriteResult, error)

UpdateProduct replaces a product in the database with the given item. If a product with the given id does not exist in the database this function returns a ProductNotFound error

type Validation

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

Validation contains a validate

func NewValidation

func NewValidation() *Validation

NewValidation creates a new Validation type

func (*Validation) Validate

func (v *Validation) Validate(i interface{}) ValidationErrors

Validate the item

type ValidationError

type ValidationError struct {
	FieldError validator.FieldError
}

ValidationError wraps the validator.FieldError so it is not exposed to our code

func (ValidationError) Error

func (v ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of ValidationError

func (ValidationErrors) Errors

func (v ValidationErrors) Errors() []string

Errors converts the slice into a string slice

Jump to

Keyboard shortcuts

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