assetdomain

package
v0.0.0-...-44f2542 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const AggregateType = "asset"

AggregateType represents the asset aggregate type.

Variables

View Source
var (
	// ErrMoneyAmountCannotBeNegative represents the error when the money amount is negative.
	ErrMoneyAmountCannotBeNegative = errors.New("money amount cannot be negative")

	// ErrUnsupportedCurrency represents the error when the money currency is invalid.
	ErrUnsupportedCurrency = errors.New("currency not supported, please use USD or EUR")
)
View Source
var (
	// ErrAssetNameIsRequired represents the error when the asset name is required.
	ErrAssetNameIsRequired = errors.New("asset name is required")

	// ErrAssetTypeIsRequired represents the error when the asset type is required.
	ErrAssetTypeIsRequired = errors.New("asset type is required")

	// ErrAssetMoneyIsInvalid represents the error when the asset money is invalid.
	ErrAssetMoneyIsInvalid = errors.New("asset money is invalid")

	// ErrAssetNotFound represents the error when the asset is not found.
	ErrAssetNotFound = errors.New("asset not found")

	// ErrAssetAlreadyExists represents the error when the asset already exists.
	ErrAssetAlreadyExists = errors.New("asset already exists with given identifier")
)
View Source
var (
	// ErrInvalidAssetType represents the error when the asset type is invalid.
	ErrInvalidAssetType = errors.New("invalid asset type")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	*aggregate.Base[uuid.UUID]
	// contains filtered or unexported fields
}

Asset represents any resource owned or controlled by a business or an economic entity that can be converted into cash.

func HydrateAsset

func HydrateAsset(id uuid.UUID, events []aggregate.Change) (*Asset, error)

func NewAsset

func NewAsset(id uuid.UUID, name string, assetType AssetType, money Money) (*Asset, error)

NewAsset creates a new Asset instance with the given data.

func (*Asset) ID

func (a *Asset) ID() uuid.UUID

ID returns the asset ID.

func (*Asset) IsDeleted

func (a *Asset) IsDeleted() bool

IsDeleted checks if the asset is deleted.

func (*Asset) MarkAsDeleted

func (a *Asset) MarkAsDeleted()

MarkAsDeleted deletes the asset by given ID.

func (*Asset) Money

func (a *Asset) Money() Money

Money returns the asset money.

func (*Asset) Name

func (a *Asset) Name() string

Name returns the asset name.

func (*Asset) Type

func (a *Asset) Type() AssetType

Type returns the asset type.

func (*Asset) Validate

func (a *Asset) Validate() error

Validate validates the asset.

type AssetType

type AssetType string

AssetType represents the asset type.

const (
	// AssetTypeCash represents the cash asset type.
	AssetTypeCash AssetType = "cash"

	// AssetTypeBank represents the bank asset type.
	AssetTypeBank AssetType = "bank"

	// AssetTypeInvestment represents the investment asset type.
	AssetTypeInvestment AssetType = "investment"

	// AssetTypeOther represents the other asset type.
	AssetTypeOther AssetType = "other"
)

func (AssetType) String

func (at AssetType) String() string

String returns the string representation of the asset type.

func (AssetType) Validate

func (at AssetType) Validate() error

Validate validates the asset type.

type Currency

type Currency string

Currency returns the money currency code.

const (
	// USD represents the US Dollar currency.
	USD Currency = "USD"

	// EUR represents the Euro currency.
	EUR Currency = "EUR"
)

func (Currency) IsValid

func (c Currency) IsValid() bool

IsValid checks if the currency code is valid.

func (Currency) String

func (c Currency) String() string

String returns the currency code as a string.

type Money

type Money struct {
	Amount   float64
	Currency Currency
}

Money represents the asset money.

func NewMoney

func NewMoney(amount float64, currency string) (Money, error)

NewMoney creates a new Money object with the given amount and currency.

func (Money) Validate

func (m Money) Validate() error

type Repository

type Repository interface {
	// Save saves all the asset uncommited events to the event store
	Save(ctx context.Context, asset *Asset) error

	// GetByID returns the asset by the given ID
	GetByID(ctx context.Context, id uuid.UUID) (*Asset, error)

	// GetAll returns all the assets
	GetAll(ctx context.Context) ([]*Asset, error)

	// Exists checks if an asset with the given ID exists
	Exists(ctx context.Context, id uuid.UUID) (bool, error)
}

Repository is the interface that wraps the basic asset repository methods.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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