homebus

package
v0.0.0-...-78d125d Latest Latest
Warning

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

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

Documentation

Overview

Package homebus provides business access to home domain.

Index

Constants

View Source
const (
	OrderByID     = "home_id"
	OrderByType   = "type"
	OrderByUserID = "user_id"
)

Set of fields that the results can be ordered by.

Variables

View Source
var (
	ErrNotFound     = errors.New("home not found")
	ErrUserDisabled = errors.New("user disabled")
)

Set of error variables for CRUD operations.

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

DefaultOrderBy represents the default way we sort.

Functions

This section is empty.

Types

type Address

type Address struct {
	Address1 string // We should create types for these fields.
	Address2 string
	ZipCode  string
	City     string
	State    string
	Country  string
}

Address represents an individual address.

func ParseAddress

func ParseAddress(address1 string, address2 string, zipCode string, city string, state string, country string) Address

ParseAddress is a helper function to create an address value.

type Business

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

Business manages the set of APIs for home api access.

func NewBusiness

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

NewBusiness constructs a home business API for use.

func (*Business) Count

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

Count returns the total number of homes.

func (*Business) Create

func (b *Business) Create(ctx context.Context, nh NewHome) (Home, error)

Create adds a new home to the system.

func (*Business) Delete

func (b *Business) Delete(ctx context.Context, hme Home) error

Delete removes the specified home.

func (*Business) NewWithTx

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

NewWithTx constructs a new domain 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) ([]Home, error)

Query retrieves a list of existing homes.

func (*Business) QueryByID

func (b *Business) QueryByID(ctx context.Context, homeID uuid.UUID) (Home, error)

QueryByID finds the home by the specified ID.

func (*Business) QueryByUserID

func (b *Business) QueryByUserID(ctx context.Context, userID uuid.UUID) ([]Home, error)

QueryByUserID finds the homes by a specified User ID.

func (*Business) Update

func (b *Business) Update(ctx context.Context, hme Home, uh UpdateHome) (Home, error)

Update modifies information about a home.

type Home

type Home struct {
	ID          uuid.UUID
	UserID      uuid.UUID
	Type        hometype.HomeType
	Address     Address
	DateCreated time.Time
	DateUpdated time.Time
}

Home represents an individual home.

func TestGenerateSeedHomes

func TestGenerateSeedHomes(ctx context.Context, n int, api *Business, userID uuid.UUID) ([]Home, error)

TestGenerateSeedHomes is a helper method for testing.

type NewHome

type NewHome struct {
	UserID  uuid.UUID
	Type    hometype.HomeType
	Address Address
}

NewHome is what we require from clients when adding a Home.

func TestGenerateNewHomes

func TestGenerateNewHomes(n int, userID uuid.UUID) []NewHome

TestGenerateNewHomes is a helper method for testing.

type QueryFilter

type QueryFilter struct {
	ID               *uuid.UUID
	UserID           *uuid.UUID
	Type             *hometype.HomeType
	StartCreatedDate *time.Time
	EndCreatedDate   *time.Time
}

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

type Storer

type Storer interface {
	NewWithTx(tx sqldb.CommitRollbacker) (Storer, error)
	Create(ctx context.Context, hme Home) error
	Update(ctx context.Context, hme Home) error
	Delete(ctx context.Context, hme Home) error
	Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]Home, error)
	Count(ctx context.Context, filter QueryFilter) (int, error)
	QueryByID(ctx context.Context, homeID uuid.UUID) (Home, error)
	QueryByUserID(ctx context.Context, userID uuid.UUID) ([]Home, error)
}

Storer interface declares the behaviour this package needs to persist and retrieve data.

type UpdateAddress

type UpdateAddress struct {
	Address1 *string
	Address2 *string
	ZipCode  *string
	City     *string
	State    *string
	Country  *string
}

UpdateAddress is what fields can be updated in the store.

type UpdateHome

type UpdateHome struct {
	Type    *hometype.HomeType
	Address *UpdateAddress
}

UpdateHome defines what information may be provided to modify an existing Home. All fields are optional so clients can send only the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exception around marshalling/unmarshalling.

Directories

Path Synopsis
stores
homedb
Package homedb contains home related CRUD functionality.
Package homedb contains home related CRUD functionality.

Jump to

Keyboard shortcuts

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