productapp

package
v0.0.0-...-c624722 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 12 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, productID string) error

Delete removes a product from the system.

func (*App) Query

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

Query returns a list of products with paging.

func (*App) QueryByID

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

QueryByID returns a product by its ID.

func (*App) Update

func (a *App) Update(ctx context.Context, productID string, 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) 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.

type QueryParams

type QueryParams struct {
	Page     string `query:"page"`
	Rows     string `query:"rows"`
	OrderBy  string `query:"orderBy"`
	ID       string `query:"product_id"`
	Name     string `query:"name"`
	Cost     string `query:"cost"`
	Quantity string `query:"quantity"`
}

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) 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