homebus

package
v0.0.0-...-c624722 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 11 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 (
	TypeSingle = newType("SINGLE FAMILY")
	TypeCondo  = newType("CONDO")
)

Set of possible roles for a housing type.

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
	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(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) ExecuteUnderTransaction

func (b *Business) ExecuteUnderTransaction(tx transaction.Transaction) (*Business, error)

ExecuteUnderTransaction constructs a new Core 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, pageNumber int, rowsPerPage int) ([]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        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.

func (*QueryFilter) Validate

func (qf *QueryFilter) Validate() error

Validate can perform a check of the data against the validate tags.

func (*QueryFilter) WithEndCreatedDate

func (qf *QueryFilter) WithEndCreatedDate(endDate time.Time)

WithEndCreatedDate sets the EndCreatedDate field of the QueryFilter value.

func (*QueryFilter) WithHomeID

func (qf *QueryFilter) WithHomeID(homeID uuid.UUID)

WithHomeID sets the ID field of the QueryFilter value.

func (*QueryFilter) WithHomeType

func (qf *QueryFilter) WithHomeType(homeType Type)

WithHomeType sets the Type field of the QueryFilter value.

func (*QueryFilter) WithStartDateCreated

func (qf *QueryFilter) WithStartDateCreated(startDate time.Time)

WithStartDateCreated sets the StartCreatedDate field of the QueryFilter value.

func (*QueryFilter) WithUserID

func (qf *QueryFilter) WithUserID(userID uuid.UUID)

WithUserID sets the ID field of the QueryFilter value.

type Storer

type Storer interface {
	ExecuteUnderTransaction(tx transaction.Transaction) (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, pageNumber int, rowsPerPage int) ([]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 MustParseType

func MustParseType(value string) Type

MustParseType parses the string value and returns a type if one exists. If an error occurs the function panics.

func ParseType

func ParseType(value string) (Type, error)

ParseType parses the string value and returns a type if one exists.

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) Name

func (t Type) Name() string

Name 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