product

package
v0.0.0-...-0b7f443 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decimal

type Decimal int64

Decimal ..

type ProductItem

type ProductItem struct {
	ID           int64   `json:"id"`
	Name         string  `json:"name"`
	Price        Decimal `json:"price"`
	Manufacturer string  `json:"manufacturer"`
}

ProductItem ..

func (ProductItem) Validate

func (item ProductItem) Validate() error

Validate ..

type Repository

type Repository interface {
	GetProducts(ctx context.Context, page int64, pageSize int64) ([]ProductItem, error)
	GetProductByID(ctx context.Context, id int64) (ProductItem, error)
	AddProduct(ctx context.Context, item *ProductItem) (ProductItem, error)
	UpdateProduct(ctx context.Context, item *ProductItem) (ProductItem, error)
	RemoveProduct(ctx context.Context, id int64) (int64, error)
}

Repository ..

func NewRepository

func NewRepository(DBConn *sql.DB) Repository

NewRepository ..

type Service

type Service interface {
	GetProducts(ctx context.Context, page int64, pageSize int64) ([]ProductItem, error)
	GetProductByID(ctx context.Context, id int64) (ProductItem, error)
	AddProduct(
		ctx context.Context,
		name string,
		price Decimal,
		manufacturer string,
	) (ProductItem, error)
	UpdateProduct(
		ctx context.Context,
		id int64,
		name string,
		price Decimal,
		manufacturer string,
	) (ProductItem, ServiceError)
	RemoveProduct(ctx context.Context, id int64) (int64, ServiceError)
}

Service ..

func NewService

func NewService(repository Repository) Service

NewService ..

type ServiceError

type ServiceError interface {
	Message() string
	StatusCode() ServiceStatusCode
}

ServiceError ..

func CreateServiceError

func CreateServiceError(message string, statusCode ServiceStatusCode) ServiceError

CreateServiceError ..

type ServiceStatusCode

type ServiceStatusCode string

ServiceStatusCode ..

const (
	// ItemNotFound ..
	ItemNotFound ServiceStatusCode = "ItemNotFound"

	// InvalidItem ..
	InvalidItem ServiceStatusCode = "InvalidItem"

	// UnknownException ..
	UnknownException ServiceStatusCode = "UnknownException"
)

Jump to

Keyboard shortcuts

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