inmemory

package
v0.0.0-...-14d7d22 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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

func NewAdapter(options ...Option) *Adapter

NewAdapter returns a new in-memory adapter.

func (*Adapter) CreateCart

func (a *Adapter) CreateCart(_ context.Context, userID, id string, positions map[string]int) error

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

func (a *Adapter) CreateProduct(_ context.Context, id, name string, price int) error

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

func (a *Adapter) CreateUser(_ context.Context, id string, name string, password string) error

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

func (a *Adapter) DeleteCartOfUser(_ context.Context, userID, id string) error

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

func (a *Adapter) DeleteOrderOfUser(_ context.Context, userID, id string) error

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

func (a *Adapter) FindAllProducts(_ context.Context) ([]*model.Product, error)

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

func (a *Adapter) FindCartOfUser(_ context.Context, userID, id string) (*model.Cart, error)

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

func (a *Adapter) FindOrderOfUser(_ context.Context, userID, id string) (*model.Order, error)

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

func (a *Adapter) FindProduct(ctx context.Context, id string) (*model.Product, error)

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

func (a *Adapter) FindValidCoupon(ctx context.Context, code string) (*model.Coupon, error)

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

func (a *Adapter) LockCartOfUser(ctx context.Context, userID, id string) error

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

func (a *Adapter) LockOrderOfUser(ctx context.Context, userID, id string) error

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.

Jump to

Keyboard shortcuts

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