beer

package
v0.0.0-...-fd07f43 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCashAmount = 999999999.9
	MinCashAmount = 0.1
)

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(r *routing.RouteGroup, service Service, logger log.Logger)

RegisterHandlers sets up the routing of the HTTP handlers.

Types

type BeerBox

type BeerBox struct {
	//
	PriceTotal float64 `json:"price_total"`
}

BeerBox represents the data about a price of beer box.

swagger:model

type BeerItem

type BeerItem struct {
	entity.Beer
}

BeerItem represents the data about a beer.

type CreateBeerRequest

type CreateBeerRequest struct {
	Name     string  `json:"name"`
	Brewery  string  `json:"brewery"`
	Country  string  `json:"country"`
	Price    float32 `json:"price"`
	Currency string  `json:"currency"`
}

CreateBeerRequest represents a beer creation request.

func (CreateBeerRequest) Validate

func (m CreateBeerRequest) Validate() error

Validate validates the CreateBeerRequest fields.

type Repository

type Repository interface {
	// Get returns the beer with the specified user ID.
	Get(ctx context.Context, id int) (entity.Beer, error)
	// Count returns the number of beers.
	Count(ctx context.Context) (int, error)
	// Query returns the list of beers with the given offset and limit.
	Query(ctx context.Context, offset, limit int, filters map[string]interface{}) ([]entity.Beer, error)
	// Create saves a new beer in the storage.
	Create(ctx context.Context, beer entity.Beer) (int, error)
	// GetPrice returns the price of beer box relative to currency
	GetPrice(ctx context.Context, id int, srcCurrency, dstCurrency string) (float32, error)
}

Repository encapsulates the logic to access users from the data source.

func NewRepository

func NewRepository(cc protos.CurrencyClient, db *dbcontext.DB, logger log.Logger) Repository

NewRepository creates a new beer repository

type Service

type Service interface {
	Get(ctx context.Context, id int) (BeerItem, error)
	GetPrice(ctx context.Context, id int, currency string, quantity uint32) (BeerBox, error)
	Create(ctx context.Context, input CreateBeerRequest) (BeerItem, error)
	Query(ctx context.Context, offset, limit int, filters map[string]interface{}) ([]BeerItem, error)
	Count(ctx context.Context) (int, error)
}

Service encapsulates use case logic for beers.

func NewService

func NewService(repo Repository, logger log.Logger) Service

NewService creates a new user service.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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