model

package
v0.0.0-...-f158767 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProductCategories = map[ProductCategory]string{
		Home:          "Home",
		Clothing:      "Clothing",
		Shoes:         "Shoes",
		Sport:         "Sport",
		Appliances:    "Appliances",
		Technology:    "Technology",
		Entertainment: "Entertainment",
		Books:         "Books",
		Cars:          "Cars",
	}
)

Functions

func IsValidOrderStatus

func IsValidOrderStatus(status OrderStatus) bool

func ValidateAddress

func ValidateAddress(address *Address) error

func ValidateComment

func ValidateComment(comment *Comment, exists bool) error

func ValidateImage

func ValidateImage(image *Image, exists bool) error

func ValidateInvoice

func ValidateInvoice(invoice *Invoice, exists bool) error

func ValidateItem

func ValidateItem(item *Item, exists bool) error

func ValidateOrder

func ValidateOrder(order *Order, exists bool) error

func ValidatePrice

func ValidatePrice(price *Price) error

func ValidateProduct

func ValidateProduct(product *Product, exists bool) error

func ValidateRating

func ValidateRating(rating *Rating) error

func ValidateUser

func ValidateUser(user *User, exists bool) error

Types

type Address

type Address struct {
	ID         NullInt64JSON  `json:"id"`
	City       NullStringJSON `json:"city"`
	Country    NullStringJSON `json:"country"`
	Address    NullStringJSON `json:"address"`
	PostalCode NullStringJSON `json:"postalCode"`
}

type Comment

type Comment struct {
	ID        NullInt64JSON  `json:"id"`
	User      User           `json:"user"`
	ProductID NullInt64JSON  `json:"productId"`
	Comment   NullStringJSON `json:"comment"`
	CreatedAt NullStringJSON `json:"createdAt"`
}

type Currency

type Currency int
const (
	BGN Currency = iota + 1
	// USD
	// EUR
	InvalidCurrency
)

type Image

type Image struct {
	ID        NullInt64JSON `json:"id"`
	ProductID NullInt64JSON `json:"productId"`
	Data      string        `json:"data"`
	Format    string        `json:"format"`
}

type Invoice

type Invoice struct {
	ID         NullInt64JSON  `json:"id"`
	UserID     NullInt64JSON  `json:"userId"`
	Order      Order          `json:"order"`
	TotalPrice Price          `json:"totalPrice"`
	CreatedAt  NullStringJSON `json:"createdAt"`
}

type Item

type Item struct {
	ID        NullInt64JSON `json:"id"`
	ProductID NullInt64JSON `json:"productId"`
	OrderID   NullInt64JSON `json:"orderId"`
	Quantity  NullInt64JSON `json:"quantity"`
	Price     Price         `json:"price"`
}

type NullBoolJSON

type NullBoolJSON sql.NullBool

func (NullBoolJSON) MarshalJSON

func (n NullBoolJSON) MarshalJSON() ([]byte, error)

func (*NullBoolJSON) Scan

func (n *NullBoolJSON) Scan(value interface{}) error

func (*NullBoolJSON) UnmarshalJSON

func (n *NullBoolJSON) UnmarshalJSON(data []byte) error

func (NullBoolJSON) Value

func (n NullBoolJSON) Value() (driver.Value, error)

type NullFloat64JSON

type NullFloat64JSON sql.NullFloat64

func (NullFloat64JSON) MarshalJSON

func (n NullFloat64JSON) MarshalJSON() ([]byte, error)

func (*NullFloat64JSON) Scan

func (n *NullFloat64JSON) Scan(value interface{}) error

func (*NullFloat64JSON) UnmarshalJSON

func (n *NullFloat64JSON) UnmarshalJSON(data []byte) error

func (NullFloat64JSON) Value

func (n NullFloat64JSON) Value() (driver.Value, error)

type NullInt64JSON

type NullInt64JSON sql.NullInt64

func (NullInt64JSON) MarshalJSON

func (n NullInt64JSON) MarshalJSON() ([]byte, error)

func (*NullInt64JSON) Scan

func (n *NullInt64JSON) Scan(value any) error

func (*NullInt64JSON) UnmarshalJSON

func (n *NullInt64JSON) UnmarshalJSON(data []byte) error

func (NullInt64JSON) Value

func (n NullInt64JSON) Value() (driver.Value, error)

type NullStringJSON

type NullStringJSON sql.NullString

func (NullStringJSON) MarshalJSON

func (n NullStringJSON) MarshalJSON() ([]byte, error)

func (*NullStringJSON) Scan

func (n *NullStringJSON) Scan(value interface{}) error

func (*NullStringJSON) UnmarshalJSON

func (n *NullStringJSON) UnmarshalJSON(data []byte) error

func (NullStringJSON) Value

func (n NullStringJSON) Value() (driver.Value, error)

type Order

type Order struct {
	ID           NullInt64JSON  `json:"id"`
	UserID       NullInt64JSON  `json:"userId"`
	Products     []*Item        `json:"products"`
	Status       OrderStatus    `json:"status"`
	Address      Address        `json:"address"`
	CreatedAt    NullStringJSON `json:"createdAt"`
	LatestUpdate NullStringJSON `json:"latestUpdate"`
}

type OrderStatus

type OrderStatus int
const (
	InCart OrderStatus = iota + 1
	InProgress
	Completed
	Canceled
	InvalidOrderStatus
)

type Price

type Price struct {
	Units    int64    `json:"units,omitempty"`
	Currency Currency `json:"currency,omitempty"`
}

func FromString

func FromString(s string) (Price, error)

func NewPrice

func NewPrice(units int64, currency Currency) Price

func (Price) Add

func (p Price) Add(other Price) Price

func (Price) Multiply

func (p Price) Multiply(factor float64) Price

func (Price) MultiplyInt

func (p Price) MultiplyInt(factor int) Price

func (Price) Subtract

func (p Price) Subtract(other Price) Price

func (Price) ToString

func (p Price) ToString() string

type Product

type Product struct {
	ID           NullInt64JSON   `json:"id"`
	Name         NullStringJSON  `json:"name"`
	Description  NullStringJSON  `json:"description"`
	Price        Price           `json:"price"`
	Quantity     NullInt64JSON   `json:"quantity"`
	Category     ProductCategory `json:"category"`
	Available    NullBoolJSON    `json:"available"`
	Comments     []*Comment      `json:"comments"`
	Rating       NullFloat64JSON `json:"rating"`
	RatingsCount NullInt64JSON   `json:"ratingsCount"`
	Ratings      []*Rating       `json:"-"`
	CreatedAt    NullStringJSON  `json:"createdAt"`
	UserID       NullInt64JSON   `json:"userId"`
}

type ProductCategory

type ProductCategory int
const (
	Home ProductCategory = 1 << iota
	Clothing
	Shoes
	Sport
	Appliances
	Technology
	Entertainment
	Books
	Cars
	ProductCategoryMask = 1<<iota - 1
)

type Rating

type Rating struct {
	UserID    NullInt64JSON `json:"userId"`
	ProductID NullInt64JSON `json:"productId"`
	Rating    NullInt64JSON `json:"rating"`
}

type User

type User struct {
	ID         NullInt64JSON  `json:"id"`
	Name       NullStringJSON `json:"name"`
	FirstName  NullStringJSON `json:"firstName"`
	LastName   NullStringJSON `json:"lastName"`
	PictureURL NullStringJSON `json:"pictureUrl"`
	Email      NullStringJSON `json:"email"`
	Address    Address        `json:"address"`
	CreatedAt  NullStringJSON `json:"createdAt"`
}

type ValidationError

type ValidationError struct {
	Message string `json:"message"`
	Err     error  `json:"error"`
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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