Documentation ¶
Index ¶
- Variables
- type Cart
- func (c *Cart) CreateAndGet(ctx context.Context, cart *model.Cart) (*model.Cart, error)
- func (c *Cart) Delete(ctx context.Context, cartID string) error
- func (c *Cart) Get(ctx context.Context, cartID string) (*model.Cart, error)
- func (c *Cart) GetAllUnlocked(ctx context.Context) ([]*model.Cart, error)
- func (c *Cart) UpdateAndGet(ctx context.Context, cart *model.Cart) (*model.Cart, error)
- type Order
- type Product
- func (c *Product) Get(ctx context.Context, productID string) (*model.Product, error)
- func (c *Product) GetAll(ctx context.Context) ([]*model.Product, error)
- func (c *Product) GetCoupon(ctx context.Context, code string) (*model.Coupon, error)
- func (c *Product) SaveCoupon(ctx context.Context, coupon *model.Coupon) (*model.Coupon, error)
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrConflict = errors.New("conflict") ErrForbidden = errors.New("forbidden") ErrDeleted = errors.New("deleted") ErrLocked = errors.New("locked") )
controller errors
Functions ¶
This section is empty.
Types ¶
type Cart ¶
type Cart struct { CartRepository persistence.CartRepository ProductRepository persistence.ProductRepository }
Cart is the controller that handles carts.
func (*Cart) CreateAndGet ¶
CreateAndGet creates the given cart. ErrConflict is returned if a cart with the same id already exists or existed. The cart is returned with all prices already calculated.
func (*Cart) Delete ¶
Delete deletes the cart with the given id. ErrNotFound is retuned if there is no cart with the id. ErrDeleted is returned if the cart did exist but is deleted. ErrForbidden is returned if the cart exists, but the current user is not allowed to delete it.
func (*Cart) Get ¶
Get returns the cart with the given id with all prices calculated. ErrNotFound is retuned if there is no cart with the id. ErrDeleted is returned if the cart did exist but is deleted. ErrForbidden is returned if the cart exists, but the current user is not allowed to access it.
func (*Cart) GetAllUnlocked ¶
GetAllUnlocked returns all unlocked carts of the current user.
func (*Cart) UpdateAndGet ¶
UpdateAndGet updates the given cart. ErrNotFound is returned if the cart with the same id does not exist. ErrDeleted is returned if the cart did exist but is deleted. ErrForbidden is returned if the cart exists, but updating it is not allowed for the current user. The cart is returned with all prices already calculated.
type Order ¶
type Order struct { OrderRepository persistence.OrderRepository CartRepository persistence.CartRepository ProductRepository persistence.ProductRepository CouponRepository persistence.CouponRepository PlacedOrderRepository persistence.PlacedOrderRepository }
Order is the controller that handles orders.
func (*Order) CreateAndGet ¶
CreateAndGet creates the given order. The order is returned with a unique id.
func (*Order) Delete ¶
Delete deletes the order with the given id. ErrNotFound is returned if the order does not exist. ErrDeleted is returned if the order is already deleted. ErrForbidden is returned if the order exists, but is not owned by the current user. ErrLocked is returned if the order is already placed and therefore cannot be deleted.
func (*Order) Place ¶
Place places the order with the given id. ErrNotFound is returned if the order does not exist. ErrDeleted is returned if the order used to exist, but is deleted. ErrForbidden is returned if the order exists, but is not owned by the current user. ErrLocked is returned if the order is already placed.
type Product ¶
type Product struct { ProductRepository persistence.ProductRepository CouponRepository persistence.CouponRepository }
Product is the controller that handles products.
func (*Product) Get ¶
Get returns the requested product. ErrNotFound is returned if there is no product with the given id.
func (*Product) GetCoupon ¶
GetCoupon returns the valid coupon with the given code. ErrNotFound is returned if there is no coupon with the given code or it is invalid.
func (*Product) SaveCoupon ¶
SaveCoupon creates or updates the given coupon. The coupon's code is expected to be 6 to 40 runes long, and the coupon's name 1 to 100. The coupon's product is expected to exist and the coupon's discount is expected to be between 1 and 100. On success the coupon is returned.
type User ¶
type User struct {
UserRepository persistence.UserRepository
}
User is the controller that creates a user.