Documentation
¶
Index ¶
- type Adapter
- func (a *Adapter) CreateCart(_ context.Context, userID, id string, positions map[string]int) error
- func (a *Adapter) CreateOrder(_ context.Context, userID, id string, attributes persistence.OrderAttributes) error
- func (a *Adapter) CreateProduct(_ context.Context, id, name string, price int) error
- func (a *Adapter) CreateUser(_ context.Context, id string, name string, password string) error
- func (a *Adapter) DeleteCartOfUser(_ context.Context, userID, id string) error
- func (a *Adapter) DeleteOrderOfUser(_ context.Context, userID, id string) error
- func (a *Adapter) FindAllProducts(_ context.Context) ([]*model.Product, error)
- func (a *Adapter) FindAllUnlockedCartsOfUser(_ context.Context, userID string) ([]*model.Cart, error)
- func (a *Adapter) FindCartOfUser(_ context.Context, userID, id string) (*model.Cart, error)
- func (a *Adapter) FindOrderOfUser(_ context.Context, userID, id string) (*model.Order, error)
- func (a *Adapter) FindProduct(ctx context.Context, id string) (*model.Product, error)
- func (a *Adapter) FindUserByIDAndPassword(_ context.Context, id string, password string) (*model.User, error)
- func (a *Adapter) FindUserByNameAndPassword(_ context.Context, name string, password string) (*model.User, error)
- func (a *Adapter) FindValidCoupon(ctx context.Context, code string) (*model.Coupon, error)
- func (a *Adapter) LockCartOfUser(ctx context.Context, userID, id string) error
- func (a *Adapter) LockOrderOfUser(ctx context.Context, userID, id string) error
- func (a *Adapter) StoreCoupon(ctx context.Context, code string, name string, productID string, discount int, ...) error
- func (a *Adapter) UpdateCartOfUser(_ context.Context, userID, id string, positions map[string]int) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is the in-memory persistence adapter. It implements a range of repositories. Please use NewAdapter to create a new instance. Adapter is safe for concurrent use.
func NewAdapter ¶
NewAdapter returns a new in-memory adapter.
func (*Adapter) CreateCart ¶
CreateCart creates a cart for the given user with the given id and positions. Id must be unique. ErrConflict is returned otherwise. Positions maps product ids to quantity.
func (*Adapter) CreateOrder ¶
func (a *Adapter) CreateOrder(_ context.Context, userID, id string, attributes persistence.OrderAttributes) error
CreateOrder creates an order for the given user with the given id and attributes. Id must be unique. ErrConflict is returned otherwise.
func (*Adapter) CreateProduct ¶
CreateProduct creates a product with the given id, name and price. Id must be unique. ErrConflict is returned otherwise. The price is in cents.
func (*Adapter) CreateUser ¶
CreateUser creates a user with the given id, name and password. Id must be unique. Name must be unique. ErrConflict is returned otherwise. The password is stored as a hash and can never be retrieved again.
func (*Adapter) DeleteCartOfUser ¶
DeleteCartOfUser deletes the cart of the given user with the given cart id. ErrNotFound is returned if there is no cart with the id. ErrDeleted is returned if the cart did exist but is deleted. ErrNotOwnedByUser is returned if the cart exists but it's not owned by the given user. ErrLocked is returned if the cart is owned by the given user, but is locked.
func (*Adapter) DeleteOrderOfUser ¶
DeleteOrderOfUser deletes the order of the given user with the given id. ErrNotFound is returned if there is no order with the id. ErrDeleted is returned if the order did exist but is deleted. ErrNotOwnedByUser is returned if the order exists but it's not owned by the given user. ErrLocked is returned if the order is owned by the given user, but is locked.
func (*Adapter) FindAllProducts ¶
FindAllProducts returns all stored products.
func (*Adapter) FindAllUnlockedCartsOfUser ¶
func (a *Adapter) FindAllUnlockedCartsOfUser(_ context.Context, userID string) ([]*model.Cart, error)
FindAllUnlockedCartsOfUser returns all stored carts and their positions of the given user.
func (*Adapter) FindCartOfUser ¶
FindCartOfUser returns the cart of the given user with the given cart id. ErrNotFound is returned if there is no cart with the id. ErrDeleted is returned if the cart did exist but is deleted. ErrNotOwnedByUser is returned if the cart exists but it's not owned by the given user.
func (*Adapter) FindOrderOfUser ¶
FindOrderOfUser returns the order of the given user with the given id. ErrNotFound is returned if there is no order with the id. ErrDeleted is returned if the order did exist but is deleted. ErrNotOwnedByUser is returned if the order exists but it's not owned by the given user.
func (*Adapter) FindProduct ¶
FindProduct returns the product with the given id. ErrNotFound is returned if there is no product with the id.
func (*Adapter) FindUserByIDAndPassword ¶
func (a *Adapter) FindUserByIDAndPassword(_ context.Context, id string, password string) (*model.User, error)
FindUserByIDAndPassword finds the user by the given id and password. As ids are unique the result is unambiguous. ErrNotFound is returned if no user matches the set of id and password.
func (*Adapter) FindUserByNameAndPassword ¶
func (a *Adapter) FindUserByNameAndPassword(_ context.Context, name string, password string) (*model.User, error)
FindUserByNameAndPassword finds the user by the given name and password. As names are unique the result is unambiguous. ErrNotFound is returned if no user matches the set of name and password.
func (*Adapter) FindValidCoupon ¶
FindValidCoupon returns the coupon with the given code that is not expired. ErrNotFound is returned if there is no coupon with the code or the coupon is expired.
func (*Adapter) LockCartOfUser ¶
LockCartOfUser locks the cart of the given user with the given cart id. ErrNotFound is returned if there is no cart with the id. ErrDeleted is returned if the cart did exist but is deleted. ErrNotOwnedByUser is returned if the cart exists but it's not owned by the given user. ErrLocked is returned if the cart is owned by the given user, but is locked.
func (*Adapter) LockOrderOfUser ¶
LockOrderOfUser locks the order of the given user with the given id. ErrNotFound is returned if there is no order with the id. ErrDeleted is returned if the order did exist but is deleted. ErrNotOwnedByUser is returned if the order exists but it's not owned by the given user. ErrLocked is returned if the order is owned by the given user, but is locked.
func (*Adapter) StoreCoupon ¶
func (a *Adapter) StoreCoupon(ctx context.Context, code string, name string, productID string, discount int, expiresAt time.Time) error
StoreCoupon stores a coupon with the given code, name, product id, discount in percent and expires at time. If a coupon with the same code was previously stored it is overwritten.
func (*Adapter) UpdateCartOfUser ¶
func (a *Adapter) UpdateCartOfUser(_ context.Context, userID, id string, positions map[string]int) error
UpdateCartOfUser updates a cart of the given user with new positions. Any existing positions are replaced. ErrNotFound is returned if the cart does not exist. ErrDeleted is returned if the cart did exist but is deleted. ErrNotOwnedByUser is returned if the cart exists but it's not owned by the given user. ErrLocked is returned if the cart is owned by the given user, but is locked.
type Option ¶
type Option func(*Adapter)
Option can be used to configure an adapter.
func FastLessSecureHashingForTesting ¶
func FastLessSecureHashingForTesting() Option
FastLessSecureHashingForTesting is an option that configures an adapter to use a less secure hashing. It is not secure enough to use in production, but can speed up tests.