Documentation ¶
Overview ¶
package pricing implements implements storing and retrieving pricing data.
Index ¶
- func SeedExampleData(ctx context.Context, repo Repository) error
- type AddBrandRequest
- type AddBrandResponse
- type AddPriceRequest
- type App
- type Brand
- type FinalPrice
- type GetBrandRequest
- type GetBrandResponse
- type GetPriceRequest
- type GetPriceResponse
- type Handler
- type InMemoryRepository
- func (imr *InMemoryRepository) AddBrand(ctx context.Context, name string) error
- func (imr *InMemoryRepository) AddPrice(ctx context.Context, price Price) error
- func (imr *InMemoryRepository) GetBrand(ctx context.Context, name string) (Brand, error)
- func (imr *InMemoryRepository) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
- func (imr *InMemoryRepository) Shutdown(ctx context.Context) error
- type MockRepository
- func (mr *MockRepository) AddBrand(ctx context.Context, name string) error
- func (mr *MockRepository) AddPrice(ctx context.Context, price Price) error
- func (mr *MockRepository) GetBrand(ctx context.Context, name string) (Brand, error)
- func (mr *MockRepository) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
- func (mr *MockRepository) Shutdown(ctx context.Context) error
- type Postgres
- func (pg *Postgres) AddBrand(ctx context.Context, name string) error
- func (pg *Postgres) AddPrice(ctx context.Context, price Price) error
- func (pg *Postgres) GetBrand(ctx context.Context, name string) (Brand, error)
- func (pg *Postgres) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
- func (pg *Postgres) Shutdown(ctx context.Context) error
- type Price
- type Repository
- type Service
- func (srv *Service) AddBrand(ctx context.Context, name string) error
- func (srv *Service) AddPrice(ctx context.Context, price Price) error
- func (srv *Service) GetBrand(ctx context.Context, name string) (Brand, error)
- func (srv *Service) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SeedExampleData ¶
func SeedExampleData(ctx context.Context, repo Repository) error
Types ¶
type AddBrandRequest ¶
type AddBrandRequest struct {
Name string `json:"name"`
}
type AddBrandResponse ¶
type AddPriceRequest ¶
type FinalPrice ¶
type FinalPrice struct { BrandID int // BRAND_ID: foreign key of the group chain (1 = EXAMPLE). StartDate time.Time // START_DATE: date range in which the indicated price applies. EndDate time.Time // END_DATE: date range in which the indicated price applies. ProductID int // PRODUCT_ID: Product code identifier. Price int // PRICE: final selling price. Lowest unit for currency, e.g: cents Curr string // CURR: currency iso. }
type GetBrandRequest ¶
type GetBrandRequest struct {
Name string `json:"name"`
}
type GetBrandResponse ¶
type GetPriceRequest ¶
type GetPriceResponse ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler will expose our service via an "open host service"
func NewHandler ¶
type InMemoryRepository ¶
type InMemoryRepository struct {
// contains filtered or unexported fields
}
func NewInMemoryRepository ¶
func NewInMemoryRepository(ctx context.Context) (*InMemoryRepository, error)
NewInMemoryRepository returns a memory backed Repository for persisting pricing data.
func (*InMemoryRepository) AddBrand ¶
func (imr *InMemoryRepository) AddBrand(ctx context.Context, name string) error
func (*InMemoryRepository) AddPrice ¶
func (imr *InMemoryRepository) AddPrice(ctx context.Context, price Price) error
func (*InMemoryRepository) GetPrice ¶
func (imr *InMemoryRepository) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
type MockRepository ¶
type MockRepository struct { }
func NewMockRepository ¶
func NewMockRepository() *MockRepository
func (*MockRepository) AddBrand ¶
func (mr *MockRepository) AddBrand(ctx context.Context, name string) error
func (*MockRepository) AddPrice ¶
func (mr *MockRepository) AddPrice(ctx context.Context, price Price) error
func (*MockRepository) GetPrice ¶
func (mr *MockRepository) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres is an instance of the database handler and contains a connection pool for concurrent use by methods.
func NewPostgresRepository ¶
NewPostgresRepository returns a Postgres backed Repository for persisting pricing data. New also runs any migrations in the ./migrations directory and it does this over a single new connection before closing the connection and providing a Postgres connection pool for the application main use. It might be better to split this functionality and still avoid a race condition with connections. urlExample := "postgres://username:password@localhost:5432/database_name" poolSettingsExample := "?sslmode=verify-ca&pool_max_conns=10"
type Price ¶
type Price struct { BrandID int // BRAND_ID: foreign key of the group chain (1 = EXAMPLE). StartDate time.Time // START_DATE: date range in which the indicated price applies. EndDate time.Time // END_DATE: date range in which the indicated price applies. ProductID int // PRODUCT_ID: Product code identifier. Priority int // PRIORITY: Price application disambiguator. If two prices coincide in a date range, the one with higher priority (higher numerical value) is applied. Price int // PRICE: final selling price. Lowest unit for currency, e.g: cents // could be money.Money Curr string // CURR: currency iso. }
type Repository ¶
type Repository interface { AddPrice(ctx context.Context, price Price) error GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error) AddBrand(ctx context.Context, name string) error GetBrand(ctx context.Context, name string) (Brand, error) Shutdown(ctx context.Context) error }
Repository implements persisting and reading pricing data from a backend.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service contains a Repository and actions any business logic before/after interacting with the Repository.
func NewService ¶
func NewService(repo Repository) *Service
NewService creates a new Service with the supplied repository ready for reading and writing Price data.
func (*Service) GetPrice ¶
func (srv *Service) GetPrice(ctx context.Context, brandID, productID int, date time.Time) (FinalPrice, error)
GetPrice returns the final price to apply given the provided brand, product and date. Price is an integer in the currencies lowest common demoninator, For example, cents in USD, yen in JPY.