model

package
v0.0.0-...-60e6733 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Street      string `json:"street" bson:"street" binding:"required"`
	City        string `json:"city" bson:"city" binding:"required"`
	State       string `json:"state" bson:"state" binding:"required"`
	Country     string `json:"country" bson:"country" binding:"required"`
	Observation string `json:"observation" bson:"observation"`
}

func (Address) String

func (a Address) String() string

type ConfirmedOrderState

type ConfirmedOrderState struct{}

func (ConfirmedOrderState) Confirm

func (cS ConfirmedOrderState) Confirm(_ *Order) bool

func (ConfirmedOrderState) Delivered

func (cS ConfirmedOrderState) Delivered(order *Order) bool

func (ConfirmedOrderState) IsConfirmed

func (cS ConfirmedOrderState) IsConfirmed() bool

func (ConfirmedOrderState) IsDelivered

func (cS ConfirmedOrderState) IsDelivered() bool

func (ConfirmedOrderState) MarshalJSON

func (cS ConfirmedOrderState) MarshalJSON() ([]byte, error)

func (ConfirmedOrderState) String

func (cS ConfirmedOrderState) String() string

type DeliveredOrderState

type DeliveredOrderState struct{}

func (DeliveredOrderState) Confirm

func (dS DeliveredOrderState) Confirm(_ *Order) bool

func (DeliveredOrderState) Delivered

func (dS DeliveredOrderState) Delivered(_ *Order) bool

func (DeliveredOrderState) IsConfirmed

func (dS DeliveredOrderState) IsConfirmed() bool

func (DeliveredOrderState) IsDelivered

func (dS DeliveredOrderState) IsDelivered() bool

func (DeliveredOrderState) MarshalJSON

func (dS DeliveredOrderState) MarshalJSON() ([]byte, error)

func (DeliveredOrderState) String

func (dS DeliveredOrderState) String() string

type Logger

type Logger interface {
	WithFields(map[string]interface{}) Logger
	WithRequestId(context.Context) Logger
	Print(...interface{})
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Fatal(...interface{})
	Panic(...interface{})
	Printf(string, ...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
	Panicf(string, ...interface{})
}

type LoggerFields

type LoggerFields map[string]interface{}

type Order

type Order struct {
	Id              int64
	CustomerId      int64
	CreatedOn       time.Time
	UpdatedOn       time.Time
	DeliveryDate    time.Time
	State           OrderState
	Product         *Product
	DeliveryAddress Address
}

func NewOrder

func NewOrder(customerId int64, product *Product, deliveryDate time.Time, deliveryAddress Address) Order

func (*Order) Confirm

func (o *Order) Confirm() bool

Confirm returns true when order mutates

func (*Order) Delivered

func (o *Order) Delivered() bool

Delivered returns true when order mutates

func (*Order) GetProductId

func (o *Order) GetProductId() int64

func (*Order) IsConfirmed

func (o *Order) IsConfirmed() bool

func (*Order) IsDelivered

func (o *Order) IsDelivered() bool

func (*Order) StateAsString

func (o *Order) StateAsString() string

func (*Order) String

func (o *Order) String() string

type OrderRepository

type OrderRepository interface {
	FindById(ctx context.Context, id int64) (*Order, error)
	Create(ctx context.Context, order Order) (int64, error)
	Update(ctx context.Context, order Order) (bool, error)
}

type OrderState

type OrderState interface {
	// Confirm returns true when order mutates
	Confirm(order *Order) bool
	// Delivered returns true when order mutates
	Delivered(order *Order) bool
	IsConfirmed() bool
	IsDelivered() bool
	String() string
	MarshalJSON() ([]byte, error)
}

func GetStateByString

func GetStateByString(state string) (OrderState, bool)

type Paging

type Paging struct {
	Total       int `json:"total"`
	PageSize    int `json:"pageSize"`
	Pages       int `json:"pages"`
	CurrentPage int `json:"currentPage"`
}

func NewEmptyPage

func NewEmptyPage() Paging

func NewPaging

func NewPaging(total int, pageSize int, pages int, currentPage int) Paging

func (Paging) String

func (p Paging) String() string

type PagingRequest

type PagingRequest struct {
	Page int `json:"page"`
	Size int `json:"size"`
}

func NewPagingRequest

func NewPagingRequest(page, size int) PagingRequest

func (PagingRequest) String

func (pr PagingRequest) String() string

type PendingOrderState

type PendingOrderState struct{}

func (PendingOrderState) Confirm

func (pS PendingOrderState) Confirm(order *Order) bool

func (PendingOrderState) Delivered

func (pS PendingOrderState) Delivered(_ *Order) bool

func (PendingOrderState) IsConfirmed

func (pS PendingOrderState) IsConfirmed() bool

func (PendingOrderState) IsDelivered

func (pS PendingOrderState) IsDelivered() bool

func (PendingOrderState) MarshalJSON

func (pS PendingOrderState) MarshalJSON() ([]byte, error)

func (PendingOrderState) String

func (pS PendingOrderState) String() string

type Product

type Product struct {
	Id          int64   `json:"id" bson:"_id"`
	SellerId    int64   `json:"sellerId" bson:"sellerId"`
	Name        string  `json:"name" bson:"name"`
	Description string  `json:"description" bson:"description"`
	Price       float64 `json:"price" bson:"price"`
	Category    string  `json:"category" bson:"category"`
	Stock       int     `json:"stock" bson:"stock"`
}

func (*Product) Merge

func (p *Product) Merge(updateProduct UpdateProduct)

func (*Product) ReduceStock

func (p *Product) ReduceStock() bool

ReduceStock if stock < 0 returns false; otherwise decrease in 1 product stock and returns true

func (*Product) String

func (p *Product) String() string

func (*Product) ValidStock

func (p *Product) ValidStock() bool

ValidStock returns true when: stock > 0

type ProductRepository

type ProductRepository interface {
	FindById(ctx context.Context, id int64) (*Product, error)
	Create(ctx context.Context, product Product) (int64, error)
	Update(ctx context.Context, product Product) (bool, error)
	Delete(ctx context.Context, id int64) (bool, error)
	DeleteAllBySellerId(ctx context.Context, sellerId int64) (bool, error)
	FindAllBySellerId(ctx context.Context, sellerId int64) ([]Product, error)
	Search(ctx context.Context, filters ProductSearchFilter, pagingReq PagingRequest) ([]Product, Paging, error)
}

type ProductSearchFilter

type ProductSearchFilter struct {
	Name     string   `json:"name"`
	Category string   `json:"category"`
	SellerId int64    `json:"sellerId"`
	PriceMin *float64 `json:"priceMin"`
	PriceMax *float64 `json:"priceMax"`
}

func NewProductSearchFilter

func NewProductSearchFilter(name, category string, sellerId int64, priceMin, priceMax *float64) ProductSearchFilter

func (*ProductSearchFilter) ContainsAnyPriceFilter

func (f *ProductSearchFilter) ContainsAnyPriceFilter() bool

func (*ProductSearchFilter) GetPriceMaxOrDefault

func (f *ProductSearchFilter) GetPriceMaxOrDefault() float64

func (*ProductSearchFilter) GetPriceMinOrDefault

func (f *ProductSearchFilter) GetPriceMinOrDefault() float64

func (*ProductSearchFilter) String

func (f *ProductSearchFilter) String() string

type Seller

type Seller struct {
	Id    int64  `json:"id" binding:"required"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

func (*Seller) String

func (s *Seller) String() string

type SellerRepository

type SellerRepository interface {
	FindById(ctx context.Context, id int64) (*Seller, error)
}

type UpdateProduct

type UpdateProduct struct {
	Name        string  `json:"name" binding:"required"`
	Description string  `json:"description" binding:"required"`
	Price       float64 `json:"price" binding:"required,min=0"`
	Category    string  `json:"category" binding:"required"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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