home

package
v0.0.0-...-c64bf0e Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package home provides a business access to home data in the system.

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 = Type{"SINGLE FAMILY"}
	TypeCondo  = Type{"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 Core

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

Core manages the set of APIs for home api access.

func NewCore

func NewCore(log *logger.Logger, usrCore *user.Core, delegate *delegate.Delegate, storer Storer) *Core

NewCore constructs a home core API for use.

func (*Core) Count

func (c *Core) Count(ctx context.Context, filter QueryFilter) (int, error)

Count returns the total number of homes.

func (*Core) Create

func (c *Core) Create(ctx context.Context, nh NewHome) (Home, error)

Create adds a new home to the system.

func (*Core) Delete

func (c *Core) Delete(ctx context.Context, hme Home) error

Delete removes the specified home.

func (*Core) ExecuteUnderTransaction

func (c *Core) ExecuteUnderTransaction(tx transaction.Transaction) (*Core, error)

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

func (*Core) Query

func (c *Core) Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]Home, error)

Query retrieves a list of existing homes.

func (*Core) QueryByID

func (c *Core) QueryByID(ctx context.Context, homeID uuid.UUID) (Home, error)

QueryByID finds the home by the specified ID.

func (*Core) QueryByUserID

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

QueryByUserID finds the homes by a specified User ID.

func (*Core) Update

func (c *Core) 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(n int, api *Core, 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