models

package
v0.0.0-...-cb069d3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGeneralDBFail = errors.New("unexpected database error")

ErrGeneralDBFail is used to hide db errors from client

Functions

This section is empty.

Types

type Customer

type Customer struct {
	Id        int      `json:"id,omitempty"`
	FirstName string   `json:"firstName,omitempty" validate:"required,max=50"`
	LastName  string   `json:"lastName,omitempty" validate:"required,max=50"`
	Age       int      `json:"age,omitempty" validate:"required,gt=0,max=150"`
	Orders    []*Order `json:"orders,omitempty"`
}

Customer model

func (*Customer) ToProto

func (c *Customer) ToProto() *proto.Customer

Map models.Customer to proto.Customer

type EntityError

type EntityError struct {
	Entity  string
	Message string
}

EntityError represents all errors that can be exposed to the user, for example "order/product/customer not found"

func ErrNotFound

func ErrNotFound(entity string, id int) *EntityError

ErrNotFound composes "not found" errors for provided entities

func ErrOutOfInventory

func ErrOutOfInventory(entity string, id int) *EntityError

ErrOutOfInventory composes "out of inventory" errors for provided entities

func (*EntityError) Error

func (e *EntityError) Error() string

type Order

type Order struct {
	Id          int        `json:"id,omitempty"`
	Date        time.Time  `json:"date,omitempty"`
	NetAmount   float64    `json:"netamount,omitempty"`
	Tax         float64    `json:"tax,omitempty"`
	TotalAmount float64    `json:"totalamount,omitempty"`
	Products    []*Product `json:"products,omitempty"`
}

Order model

func (*Order) ToProto

func (o *Order) ToProto() *proto.Order

Map models.Order to proto.Order

type Product

type Product struct {
	Id       int     `json:"id,omitempty" validate:"required,gte=0,int"`
	Title    string  `json:"title,omitempty" validate:"required,max=50"`
	Price    float64 `json:"price,omitempty" validate:"required,gte=0,float"`
	Quantity int     `json:"quantity,omitempty" validate:"required,gte=0,int"`
}

Product model

func ProductFromProto

func ProductFromProto(product *proto.Product) *Product

ProductFromProto maps proto.Product to models.Product

func (*Product) ToProto

func (p *Product) ToProto() *proto.Product

Map models.Product to proto.Product

type SortById

type SortById []*Product

SortById implements sort.Interface and is used to sort slice of products by id

func (SortById) Len

func (a SortById) Len() int

func (SortById) Less

func (a SortById) Less(i, j int) bool

func (SortById) Swap

func (a SortById) Swap(i, j int)

type Validation

type Validation struct {
	*validator.Validate
}

Validation embeds validator and has custom validations

func NewValidation

func NewValidation() *Validation

NewValidation creates new validator and registers custom validations

type ValidationError

type ValidationError struct {
	Message string
}

ValidationError represents validation errors

func ErrFieldsNotValid

func ErrFieldsNotValid(fieldNames ...string) *ValidationError

ErrFieldsNotValid composes validation error with provided fields

func (*ValidationError) Error

func (v *ValidationError) Error() string

Jump to

Keyboard shortcuts

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