regionbus

package
v0.0.0-...-16ef530 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderByID        = "region_id"
	OrderByName      = "name"
	OrderByCode      = "code"
	OrderByCountryID = "country_id"
)

Set of fields that the results can be ordered by.

Variables

View Source
var DefaultOrderBy = order.NewBy(OrderByName, order.ASC)

DefaultOrderBy represents the default way we sort. Usually we order by id but in the case of countries, they almost always should be by their country.

View Source
var (
	ErrNotFound = fmt.Errorf("region not found")
)

Set error variables.

Functions

This section is empty.

Types

type Business

type Business struct {
	// contains filtered or unexported fields
}

Business manages the set of APIs for region access.

func NewBusiness

func NewBusiness(log *logger.Logger, delegate *delegate.Delegate, storer Storer) *Business

NewBusiness constructs a country business API for use.

func (*Business) Count

func (b *Business) Count(ctx context.Context, filter QueryFilter) (int, error)

Count returns the number of regions that match the filter.

func (*Business) NewWithTx

func (b *Business) NewWithTx(tx sqldb.CommitRollbacker) (*Business, error)

NewWithTx constructs a new business value that will use the specified transaction in any store related calls.

func (*Business) Query

func (b *Business) Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]Region, error)

Query retrieves a list of existing regions from the database.

func (*Business) QueryByID

func (b *Business) QueryByID(ctx context.Context, regionID uuid.UUID) (Region, error)

QueryByID retrieves a single region by its ID.

type QueryFilter

type QueryFilter struct {
	ID        *uuid.UUID
	CountryID *uuid.UUID
	Name      *string
	Code      *string
}

QueryFilter holds the available fields a query can be filtered on. We are using pointer semantics because the With API mutates the value.

type Region

type Region struct {
	ID        uuid.UUID
	CountryID uuid.UUID
	Name      string
	Code      string
}

NOTE: Regions are special. They are controlled solely in the database and therefore should have ONLY retrive actions available. No create, update, or delete actions are allowed. We want only the highest level admins to have any way to touch this because it denotes areas we support.

type Storer

type Storer interface {
	NewWithTx(tx sqldb.CommitRollbacker) (Storer, error)
	Count(ctx context.Context, filter QueryFilter) (int, error)
	Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]Region, error)
	QueryByID(ctx context.Context, regionID uuid.UUID) (Region, error)
}

Storer defines the database interaction methods.

Directories

Path Synopsis
stores

Jump to

Keyboard shortcuts

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