productapp

package
v0.0.0-...-c4114b5 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package productapp maintains the app layer api for the product domain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App manages the set of app layer api functions for the product domain.

func NewApp

func NewApp(productBus *productbus.Business) *App

NewApp constructs a product app API for use.

func (*App) Create

func (a *App) Create(ctx context.Context, app NewProduct) (Product, error)

Create adds a new product to the system.

func (*App) Delete

func (a *App) Delete(ctx context.Context) error

Delete removes a product from the system.

func (*App) Query

func (a *App) Query(ctx context.Context, qp QueryParams) (query.Result[Product], error)

Query returns a list of products with paging.

func (*App) QueryByID

func (a *App) QueryByID(ctx context.Context) (Product, error)

QueryByID returns a product by its Ia.

func (*App) Update

func (a *App) Update(ctx context.Context, app UpdateProduct) (Product, error)

Update updates an existing product.

type NewProduct

type NewProduct struct {
	Name     string  `json:"name" validate:"required"`
	Cost     float64 `json:"cost" validate:"required,gte=0"`
	Quantity int     `json:"quantity" validate:"required,gte=1"`
}

NewProduct defines the data needed to add a new product.

func (*NewProduct) Decode

func (app *NewProduct) Decode(data []byte) error

Decode implments the decoder interface.

func (NewProduct) Validate

func (app NewProduct) Validate() error

Validate checks the data in the model is considered clean.

type Product

type Product struct {
	ID          string  `json:"id"`
	UserID      string  `json:"userID"`
	Name        string  `json:"name"`
	Cost        float64 `json:"cost"`
	Quantity    int     `json:"quantity"`
	DateCreated string  `json:"dateCreated"`
	DateUpdated string  `json:"dateUpdated"`
}

Product represents information about an individual product.

func (Product) Encode

func (app Product) Encode() ([]byte, string, error)

Encode implments the encoder interface.

type QueryParams

type QueryParams struct {
	Page     string
	Rows     string
	OrderBy  string
	ID       string
	Name     string
	Cost     string
	Quantity string
}

QueryParams represents the set of possible query strings.

type UpdateProduct

type UpdateProduct struct {
	Name     *string  `json:"name"`
	Cost     *float64 `json:"cost" validate:"omitempty,gte=0"`
	Quantity *int     `json:"quantity" validate:"omitempty,gte=1"`
}

UpdateProduct defines the data needed to update a product.

func (*UpdateProduct) Decode

func (app *UpdateProduct) Decode(data []byte) error

Decode implments the decoder interface.

func (UpdateProduct) Validate

func (app UpdateProduct) Validate() error

Validate checks the data in the model is considered clean.

Jump to

Keyboard shortcuts

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