Documentation ¶
Overview ¶
Package product contains product related CRUD functionality.
Index ¶
- type Info
- type NewProduct
- type Store
- func (s Store) Create(ctx context.Context, traceID string, claims auth.Claims, np NewProduct, ...) (Info, error)
- func (s Store) Delete(ctx context.Context, traceID string, claims auth.Claims, productID string) error
- func (s Store) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
- func (s Store) QueryByID(ctx context.Context, traceID string, productID string) (Info, error)
- func (s Store) Update(ctx context.Context, traceID string, claims auth.Claims, productID string, ...) error
- type UpdateProduct
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { ID string `db:"product_id" json:"id"` // Unique identifier. Name string `db:"name" json:"name"` // Display name of the product. Cost int `db:"cost" json:"cost"` // Price for one item in cents. Quantity int `db:"quantity" json:"quantity"` // Original number of items available. Sold int `db:"sold" json:"sold"` // Aggregate field showing number of items sold. Revenue int `db:"revenue" json:"revenue"` // Aggregate field showing total cost of sold items. UserID string `db:"user_id" json:"user_id"` // ID of the user who created the product. DateCreated time.Time `db:"date_created" json:"date_created"` // When the product was added. DateUpdated time.Time `db:"date_updated" json:"date_updated"` // When the product record was last modified. }
Info represents an individual product.
type NewProduct ¶
type NewProduct struct { Name string `json:"name" validate:"required"` Cost int `json:"cost" validate:"required,gte=0"` Quantity int `json:"quantity" validate:"gte=1"` }
NewProduct is what we require from clients when adding a Product.
type Store ¶ added in v0.3.3
type Store struct {
// contains filtered or unexported fields
}
Store manages the set of API's for product access.
func (Store) Create ¶ added in v0.3.3
func (s Store) Create(ctx context.Context, traceID string, claims auth.Claims, np NewProduct, now time.Time) (Info, error)
Create adds a Product to the database. It returns the created Product with fields like ID and DateCreated populated.
func (Store) Delete ¶ added in v0.3.3
func (s Store) Delete(ctx context.Context, traceID string, claims auth.Claims, productID string) error
Delete removes the product identified by a given ID.
func (Store) Query ¶ added in v0.3.3
func (s Store) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
Query gets all Products from the database.
type UpdateProduct ¶
type UpdateProduct struct { Name *string `json:"name"` Cost *int `json:"cost" validate:"omitempty,gte=0"` Quantity *int `json:"quantity" validate:"omitempty,gte=1"` }
UpdateProduct defines what information may be provided to modify an existing Product. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.