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") 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 CheckoutHistoryResponse ¶
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 (*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 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 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.
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
Click to show internal directories.
Click to hide internal directories.