homebus

package
v0.0.0-...-c4114b5 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 12 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.

View Source
var Types = typeSet{
	Single: newType("SINGLE FAMILY"),
	Condo:  newType("CONDO"),
}

Types represents the set of types that can be used.

Functions

This section is empty.

Types

type Address

type Address struct {
	Address1 string
	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 transaction.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 Ib.

func (*Business) QueryByUserID

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

QueryByUserID finds the homes by a specified User Ib.

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        Type
	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    Type
	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             *Type
	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 transaction.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 Type

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

Type represents a type in the system.

func (Type) Equal

func (t Type) Equal(t2 Type) bool

Equal provides support for the go-cmp package and testing.

func (Type) MarshalText

func (t Type) MarshalText() ([]byte, error)

MarshalText implement the marshal interface for JSON conversions.

func (Type) String

func (t Type) String() string

String returns the name of the type.

func (*Type) UnmarshalText

func (t *Type) UnmarshalText(data []byte) error

UnmarshalText implement the unmarshal interface for JSON conversions.

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    *Type
	Address *UpdateAddress
}

UpdateHome defines what informaton 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 explicity blank. Normally we do not want to use pointers to basic types but we make exepction 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