controller

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (c *Cart) CreateAndGet(ctx context.Context, cart *model.Cart) (*model.Cart, error)

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

func (c *Cart) Delete(ctx context.Context, cartID string) error

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

func (c *Cart) Get(ctx context.Context, cartID string) (*model.Cart, error)

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

func (c *Cart) GetAllUnlocked(ctx context.Context) ([]*model.Cart, error)

GetAllUnlocked returns all unlocked carts of the current user.

func (*Cart) UpdateAndGet

func (c *Cart) UpdateAndGet(ctx context.Context, cart *model.Cart) (*model.Cart, error)

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

func (c *Order) CreateAndGet(ctx context.Context, order *model.Order) (*model.Order, error)

CreateAndGet creates the given order. The order is returned with a unique id.

func (*Order) Delete

func (c *Order) Delete(ctx context.Context, orderID string) error

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

func (c *Order) Place(ctx context.Context, orderID string) (*model.Order, error)

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

func (c *Product) Get(ctx context.Context, productID string) (*model.Product, error)

Get returns the requested product. ErrNotFound is returned if there is no product with the given id.

func (*Product) GetAll

func (c *Product) GetAll(ctx context.Context) ([]*model.Product, error)

GetAll gets all products.

func (*Product) GetCoupon

func (c *Product) GetCoupon(ctx context.Context, code string) (*model.Coupon, error)

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

func (c *Product) SaveCoupon(ctx context.Context, coupon *model.Coupon) (*model.Coupon, error)

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.

func (*User) Create

func (c *User) Create(ctx context.Context, name, password string) (*model.User, error)

Create creates the user. The name is expected to be 1 to 64 runes long, and the password 8 to 64. ErrConflict is returned if the name is already taken. On success the user is returned.

func (*User) GetByNameAndPassword

func (c *User) GetByNameAndPassword(ctx context.Context, name, password string) (*model.User, error)

GetByNameAndPassword gets the user by name and password. ErrNotFound is returned if there is no user with the name. On success the user is returned.

Jump to

Keyboard shortcuts

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