checkout

package
v0.0.0-...-67df6f6 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCustomerNotFound      = errors.New("customer id is not found")
	ErrProductNotFound       = errors.New("one or more products is not available")
	ErrProductUnavailable    = errors.New("product is unavailable")
	ErrProductStockNotEnough = errors.New("product stock is not enough")
	ErrNotEnoughMoney        = errors.New("not enough money paid")
	ErrWrongChange           = errors.New("wrong change")
	ErrValidationFailed      = errors.New("validation failed")
)

Functions

This section is empty.

Types

type CheckoutHistory

type CheckoutHistory struct {
	ID             string
	UserID         string
	ProductDetails ProductDetails
	Paid           int
	Change         int
	CreatedAt      time.Time
}

type CheckoutHistoryResponse

type CheckoutHistoryResponse struct {
	TransactionID  string                  `json:"transactionId"`
	CustomerID     string                  `json:"customerId"`
	ProductDetails []ProductDetailResponse `json:"productDetails"`
	Paid           int                     `json:"paid"`
	Change         int                     `json:"change"`
	CreatedAt      time.Time               `json:"createdAt"`
}

type CheckoutRequest

type CheckoutRequest struct {
	CustomerID     string                 `json:"customerId"`
	ProductDetails []ProductDetailRequest `json:"productDetails"`
	Paid           int                    `json:"paid"`
	Change         *int                   `json:"change"`
}

func (CheckoutRequest) Validate

func (p CheckoutRequest) Validate() error

type CreatedAtSearchType

type CreatedAtSearchType int
const (
	Ascending CreatedAtSearchType = iota
	Descending
	Ignore
)

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CheckoutProducts

func (h *Handler) CheckoutProducts(w http.ResponseWriter, r *http.Request)

func (*Handler) ListCheckoutHistories

func (h *Handler) ListCheckoutHistories(w http.ResponseWriter, r *http.Request)

type ListCheckoutHistoriesPayload

type ListCheckoutHistoriesPayload struct {
	CustomerID string `schema:"customerId" binding:"omitempty"`
	Limit      int    `schema:"limit" binding:"omitempty"`
	Offset     int    `schema:"offset" binding:"omitempty"`
	CreatedAt  string `schema:"createdAt" binding:"omitempty"`

	CreatedAtSearchType CreatedAtSearchType
}

type ProductDetail

type ProductDetail struct {
	ProductID string
	Quantity  int
}

type ProductDetailRequest

type ProductDetailRequest struct {
	ProductID     string `json:"productId"`
	Quantity      int    `json:"quantity"`
	OriginalStock int    `json:"originalStock"`
}

func (ProductDetailRequest) Validate

func (p ProductDetailRequest) Validate() error

type ProductDetailResponse

type ProductDetailResponse struct {
	ProductID string `json:"productId"`
	Quantity  int    `json:"quantity"`
}

type ProductDetails

type ProductDetails []ProductDetail

func (*ProductDetails) Scan

func (a *ProductDetails) Scan(value interface{}) error

Make the Attrs struct implement the sql.Scanner interface. This method simply decodes a JSON-encoded value into the struct fields.

func (ProductDetails) Value

func (a ProductDetails) Value() (driver.Value, error)

Make the Attrs struct implement the driver.Valuer interface. This method simply returns the JSON-encoded representation of the struct.

type Repository

type Repository interface {
	CreateCheckoutHistory(ctx context.Context, ch *CheckoutHistory) error
	ListCheckoutHistories(ctx context.Context, req ListCheckoutHistoriesPayload) ([]*CheckoutHistory, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Service

type Service interface {
	CheckoutProducts(ctx context.Context, req CheckoutRequest) error
	ListCheckoutHistories(ctx context.Context, req ListCheckoutHistoriesPayload) ([]*CheckoutHistoryResponse, error)
}

func NewService

func NewService(repository Repository, userRepository user.Repository, productRepository product.Repository) Service

Jump to

Keyboard shortcuts

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