Documentation ¶
Index ¶
- Variables
- func NewBasketHandler(r *gin.RouterGroup, service Service)
- func NewBasketRepository(db *gorm.DB) *basketRepository
- type AddItemRequest
- type Basket
- func (b *Basket) AddItem(sku string, price float64, quantity int) (*Item, error)
- func (b *Basket) RemoveItem(itemId string) (err error)
- func (b *Basket) SearchItem(itemId string) (int, *Item)
- func (b *Basket) SearchItemBySku(sku string) (int, *Item)
- func (b *Basket) UpdateItem(itemId string, quantity int) (err error)
- func (b *Basket) ValidateBasket() error
- type CreateBasketRequest
- type Item
- type Repository
- type Service
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("Item not found") ErrCustomerCannotBeNil = errors.New("Customer cannot be nil") )
Functions ¶
func NewBasketHandler ¶
func NewBasketHandler(r *gin.RouterGroup, service Service)
func NewBasketRepository ¶
Types ¶
type AddItemRequest ¶
type Basket ¶
type Basket struct { Id string `json:"id"` CustomerId string `json:"CustomerId"` Items []Item `json:"items"` CreatedAt time.Time `json:"createdAt"` }
func (*Basket) RemoveItem ¶
func (*Basket) ValidateBasket ¶
type CreateBasketRequest ¶
type CreateBasketRequest struct {
Buyer string `json:"buyer" validate:"required"`
}
type Repository ¶
type Repository interface { // Get returns the basket with the specified basket Id. Get(ctx context.Context, id string) *Basket // GetByCustomerId returns the basket with the specified customer Id. GetByCustomerId(ctx context.Context, customerId string) *Basket // Create saves a new basket in the storage. Create(ctx context.Context, basket *Basket) error // Update updates the basket with given Is in the storage. Update(ctx context.Context, basket Basket) error // Delete removes the basket with given Is from the storage. Delete(ctx context.Context, basket Basket) error }
Repository encapsulates the logic to access basket from the data source.
type Service ¶
type Service interface { Get(ctx context.Context, id string) (*Basket, error) GetByCustomerId(ctx context.Context, customerId string) (*Basket, error) Create(ctx context.Context, buyer string) (*Basket, error) Delete(ctx context.Context, id string) (*Basket, error) UpdateItem(ctx context.Context, basketId, itemId string, quantity int) error AddItem(ctx context.Context, basketId, sku string, quantity int, price float64) (string, error) DeleteItem(ctx context.Context, basketId, itemId string) error }
func NewBasketService ¶
func NewBasketService(repo Repository) Service
Click to show internal directories.
Click to hide internal directories.