Documentation
¶
Index ¶
Constants ¶
const ( Pending status = iota Paid Shipping Shipped Failed )
Order statuses
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Date ¶
type Date struct {
Year int `json:"year" validate:"required,min=2021,max=2150"`
Month int `json:"month" validate:"required,min=1,max=12"`
Day int `json:"day" validate:"required,min=1,max=31"`
Hour int `json:"hour" validate:"required,min=0,max=24"`
Minutes int `json:"minutes" validate:"required,min=0,max=60"`
}
Date of the order.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles ordering endpoints.
func NewHandler ¶
func NewHandler(dev bool, orderingS Service, cartS cart.Service, db *sqlx.DB, cache *memcache.Client) Handler
NewHandler returns a new ordering handler.
func (*Handler) GetByID ¶
func (h *Handler) GetByID() http.HandlerFunc
GetByID retrieves all the orders from the user.
func (*Handler) GetByUserID ¶
func (h *Handler) GetByUserID() http.HandlerFunc
GetByUserID retrieves all the orders from the user.
func (*Handler) New ¶
func (h *Handler) New() http.HandlerFunc
New creates a new order and the payment intent.
type Order ¶
type Order struct {
ID zero.String `json:"id,omitempty"`
UserID zero.String `json:"user_id,omitempty" db:"user_id"`
Currency zero.String `json:"currency,omitempty"`
Address zero.String `json:"address,omitempty"`
City zero.String `json:"city,omitempty"`
State zero.String `json:"state,omitempty"`
ZipCode zero.String `json:"zip_code,omitempty" db:"zip_code"`
Country zero.String `json:"country,omitempty"`
Status zero.Int `json:"status,omitempty"`
OrderedAt zero.Time `json:"ordered_at,omitempty" db:"ordered_at"`
DeliveryDate zero.Time `json:"delivery_date,omitempty" db:"delivery_date"`
CartID zero.String `json:"cart_id,omitempty" db:"cart_id"`
Cart OrderCart `json:"cart,omitempty"`
Products []OrderProduct `json:"products,omitempty"`
CreatedAt zero.Time `json:"created_at,omitempty" db:"created_at"`
}
Order represents a user purchase request.
type OrderCart ¶
type OrderCart struct {
OrderID zero.String `json:"order_id,omitempty" db:"order_id"`
Counter zero.Int `json:"counter,omitempty"`
Weight zero.Int `json:"weight,omitempty"`
Discount zero.Int `json:"discount,omitempty"`
Taxes zero.Int `json:"taxes,omitempty"`
Subtotal zero.Int `json:"subtotal,omitempty"`
Total zero.Int `json:"total,omitempty"`
}
OrderCart represents the cart ordered by the user.
Amounts to be provided in a currency’s smallest unit. 100 = 1 USD.
type OrderParams ¶
type OrderParams struct {
Currency string `json:"currency" validate:"required"`
Address string `json:"address" validate:"required"`
City string `json:"city" validate:"required"`
Country string `json:"country" validate:"required"`
State string `json:"state" validate:"required"`
ZipCode string `json:"zip_code" validate:"required"`
Date Date `json:"date" validate:"required"`
Card stripe.Card `json:"card" validate:"required"`
}
OrderParams holds the parameters for creating a order.
type OrderProduct ¶
type OrderProduct struct {
ProductID zero.String `json:"product_id,omitempty" db:"product_id"`
OrderID zero.String `json:"order_id,omitempty" db:"order_id"`
Quantity zero.Int `json:"quantity,omitempty"`
Brand zero.String `json:"brand,omitempty"`
Category zero.String `json:"category,omitempty"`
Type zero.String `json:"type,omitempty"`
Description zero.String `json:"description,omitempty"`
Weight zero.Int `json:"weight,omitempty"`
Discount zero.Int `json:"discount,omitempty"`
Taxes zero.Int `json:"taxes,omitempty"`
Subtotal zero.Int `json:"subtotal,omitempty"`
Total zero.Int `json:"total,omitempty"`
}
OrderProduct represents a product placed into the cart ordered by the user.
Amounts to be provided in a currency’s smallest unit. 100 = 1 USD.
type Service ¶
type Service interface {
New(ctx context.Context, id, userID string, cartID string, oParams OrderParams, cartService cart.Service) (Order, error)
Delete(ctx context.Context, orderID string) error
Get(ctx context.Context, params params.Query) ([]Order, error)
GetByID(ctx context.Context, orderID string) (Order, error)
GetByUserID(ctx context.Context, userID string) ([]Order, error)
GetCartByID(ctx context.Context, orderID string) (OrderCart, error)
GetProductsByID(ctx context.Context, orderID string) ([]OrderProduct, error)
UpdateStatus(ctx context.Context, orderID string, status status) error
}
Service contains order functionalities.