vproduct

package
v0.0.0-...-c64bf0e Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package vproduct provides an example of a core business API that is based on a view.

Index

Constants

View Source
const (
	OrderByProductID = "product_id"
	OrderByUserID    = "user_id"
	OrderByName      = "name"
	OrderByCost      = "cost"
	OrderByQuantity  = "quantity"
	OrderByUserName  = "user_name"
)

Set of fields that the results can be ordered by.

Variables

View Source
var DefaultOrderBy = order.NewBy(OrderByProductID, order.ASC)

DefaultOrderBy represents the default way we sort.

Functions

This section is empty.

Types

type Core

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

Core manages the set of APIs for user access.

func NewCore

func NewCore(storer Storer) *Core

NewCore constructs a usersummary core API for use.

func (*Core) Count

func (c *Core) Count(ctx context.Context, filter QueryFilter) (int, error)

Count returns the total number of products.

func (*Core) Query

func (c *Core) Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]Product, error)

Query retrieves a list of existing products.

type Product

type Product struct {
	ID          uuid.UUID
	UserID      uuid.UUID
	Name        string
	Cost        float64
	Quantity    int
	DateCreated time.Time
	DateUpdated time.Time
	UserName    string
}

Product represents an individual product with extended information.

type QueryFilter

type QueryFilter struct {
	ID       *uuid.UUID
	Name     *string `validate:"omitempty,min=3"`
	Cost     *float64
	Quantity *int
	UserName *string
}

QueryFilter holds the available fields a query can be filtered on. We are using pointer semantics because the With API mutates the value.

func (*QueryFilter) Validate

func (qf *QueryFilter) Validate() error

Validate can perform a check of the data against the validate tags.

func (*QueryFilter) WithCost

func (qf *QueryFilter) WithCost(cost float64)

WithCost sets the Cost field of the QueryFilter value.

func (*QueryFilter) WithID

func (qf *QueryFilter) WithID(productID uuid.UUID)

WithID sets the ID field of the QueryFilter value.

func (*QueryFilter) WithName

func (qf *QueryFilter) WithName(name string)

WithName sets the Name field of the QueryFilter value.

func (*QueryFilter) WithQuantity

func (qf *QueryFilter) WithQuantity(quantity int)

WithQuantity sets the Quantity field of the QueryFilter value.

func (*QueryFilter) WithUserName

func (qf *QueryFilter) WithUserName(userName string)

WithUserName sets the UserName field of the QueryFilter value.

type Storer

type Storer interface {
	Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]Product, error)
	Count(ctx context.Context, filter QueryFilter) (int, error)
}

Storer interface declares the behavior this package needs to perists and retrieve data.

Directories

Path Synopsis
stores
vproductdb
Package vproductdb provides access to the product view.
Package vproductdb provides access to the product view.

Jump to

Keyboard shortcuts

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