cart

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decimal

type Decimal int64

Decimal ..

type Item

type Item struct {
	ID           int64   `json:"id"`
	Name         string  `json:"name"`
	Price        Decimal `json:"price"`
	Manufacturer string  `json:"manufacturer"`
}

Item ..

func (Item) Validate

func (item Item) Validate() error

Validate ..

type Repository

type Repository interface {
	GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error)
	GetItemByID(ctx context.Context, id int64) (Item, error)
	AddItem(ctx context.Context, item *Item) (Item, error)
	UpdateItem(ctx context.Context, item *Item) (Item, error)
	RemoveItem(ctx context.Context, id int64) (int64, error)
}

Repository ..

func NewRepository

func NewRepository(DBConn *sql.DB) Repository

NewRepository ..

type RepositoryMock

type RepositoryMock struct {
	// AddItemFunc mocks the AddItem method.
	AddItemFunc func(ctx context.Context, item *Item) (Item, error)

	// GetItemByIDFunc mocks the GetItemByID method.
	GetItemByIDFunc func(ctx context.Context, id int64) (Item, error)

	// GetItemsFunc mocks the GetItems method.
	GetItemsFunc func(ctx context.Context, page int64, pageSize int64) ([]Item, error)

	// RemoveItemFunc mocks the RemoveItem method.
	RemoveItemFunc func(ctx context.Context, id int64) (int64, error)

	// UpdateItemFunc mocks the UpdateItem method.
	UpdateItemFunc func(ctx context.Context, item *Item) (Item, error)
	// contains filtered or unexported fields
}

RepositoryMock is a mock implementation of Repository.

func TestSomethingThatUsesRepository(t *testing.T) {

	// make and configure a mocked Repository
	mockedRepository := &RepositoryMock{
		AddItemFunc: func(ctx context.Context, item *Item) (Item, error) {
			panic("mock out the AddItem method")
		},
		GetItemByIDFunc: func(ctx context.Context, id int64) (Item, error) {
			panic("mock out the GetItemByID method")
		},
		GetItemsFunc: func(ctx context.Context, page int64, pageSize int64) ([]Item, error) {
			panic("mock out the GetItems method")
		},
		RemoveItemFunc: func(ctx context.Context, id int64) (int64, error) {
			panic("mock out the RemoveItem method")
		},
		UpdateItemFunc: func(ctx context.Context, item *Item) (Item, error) {
			panic("mock out the UpdateItem method")
		},
	}

	// use mockedRepository in code that requires Repository
	// and then make assertions.

}

func (*RepositoryMock) AddItem

func (mock *RepositoryMock) AddItem(ctx context.Context, item *Item) (Item, error)

AddItem calls AddItemFunc.

func (*RepositoryMock) AddItemCalls

func (mock *RepositoryMock) AddItemCalls() []struct {
	Ctx  context.Context
	Item *Item
}

AddItemCalls gets all the calls that were made to AddItem. Check the length with:

len(mockedRepository.AddItemCalls())

func (*RepositoryMock) GetItemByID

func (mock *RepositoryMock) GetItemByID(ctx context.Context, id int64) (Item, error)

GetItemByID calls GetItemByIDFunc.

func (*RepositoryMock) GetItemByIDCalls

func (mock *RepositoryMock) GetItemByIDCalls() []struct {
	Ctx context.Context
	ID  int64
}

GetItemByIDCalls gets all the calls that were made to GetItemByID. Check the length with:

len(mockedRepository.GetItemByIDCalls())

func (*RepositoryMock) GetItems

func (mock *RepositoryMock) GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error)

GetItems calls GetItemsFunc.

func (*RepositoryMock) GetItemsCalls

func (mock *RepositoryMock) GetItemsCalls() []struct {
	Ctx      context.Context
	Page     int64
	PageSize int64
}

GetItemsCalls gets all the calls that were made to GetItems. Check the length with:

len(mockedRepository.GetItemsCalls())

func (*RepositoryMock) RemoveItem

func (mock *RepositoryMock) RemoveItem(ctx context.Context, id int64) (int64, error)

RemoveItem calls RemoveItemFunc.

func (*RepositoryMock) RemoveItemCalls

func (mock *RepositoryMock) RemoveItemCalls() []struct {
	Ctx context.Context
	ID  int64
}

RemoveItemCalls gets all the calls that were made to RemoveItem. Check the length with:

len(mockedRepository.RemoveItemCalls())

func (*RepositoryMock) UpdateItem

func (mock *RepositoryMock) UpdateItem(ctx context.Context, item *Item) (Item, error)

UpdateItem calls UpdateItemFunc.

func (*RepositoryMock) UpdateItemCalls

func (mock *RepositoryMock) UpdateItemCalls() []struct {
	Ctx  context.Context
	Item *Item
}

UpdateItemCalls gets all the calls that were made to UpdateItem. Check the length with:

len(mockedRepository.UpdateItemCalls())

type Service

type Service interface {
	GetItems(ctx context.Context, page int64, pageSize int64) ([]Item, error)
	GetItemByID(ctx context.Context, id int64) (Item, error)
	AddCartItem(
		ctx context.Context,
		name string,
		price Decimal,
		manufacturer string,
	) (Item, error)
	UpdateCartItem(
		ctx context.Context,
		id int64,
		name string,
		price Decimal,
		manufacturer string,
	) (Item, ServiceError)
	RemoveCartItem(ctx context.Context, id int64) (int64, ServiceError)
}

Service ..

func NewService

func NewService(repository Repository) Service

NewService ..

type ServiceError

type ServiceError interface {
	Message() string
	StatusCode() ServiceStatusCode
}

ServiceError ..

func CreateServiceError

func CreateServiceError(message string, statusCode ServiceStatusCode) ServiceError

CreateServiceError ..

type ServiceStatusCode

type ServiceStatusCode string

ServiceStatusCode ..

const (
	// ItemNotFound ..
	ItemNotFound ServiceStatusCode = "ItemNotFound"

	// InvalidItem ..
	InvalidItem ServiceStatusCode = "InvalidItem"

	// UnknownException ..
	UnknownException ServiceStatusCode = "UnknownException"
)

Jump to

Keyboard shortcuts

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