entity

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNameEmpty     = errors.New("name is empty")
	ErrUsernameEmpty = errors.New("username is empty")
)

Functions

This section is empty.

Types

type Balance

type Balance struct {
	USD entity.USD
	BTC entity.BTC
}

func NewBalance

func NewBalance(usd entity.USD, btc entity.BTC) Balance

func (Balance) Total

func (b Balance) Total(bitcoinPrice entity.BTCPrice) entity.USD

type User

type User struct {
	ID        uint64
	Name      string
	Username  string
	Email     *mail.Address
	Balance   Balance
	CreatedAt time.Time
	UpdatedAt time.Time
}

func MustNewUser

func MustNewUser(
	id uint64,
	name string,
	username string,
	email string,
	btcBalance float64,
	usdBalance float64,
	createdAt time.Time,
	updatedAt time.Time,
) *User

func NewUser

func NewUser(
	id uint64,
	name string,
	username string,
	email string,
	btcBalance float64,
	usdBalance float64,
	createdAt time.Time,
	updatedAt time.Time,
) (*User, error)

func (*User) ChangeBTCBalance

func (u *User) ChangeBTCBalance(action domain2.BTCAction, amount domain2.BTC, price domain2.BTCPrice) error

func (*User) ChangeUSDBalance

func (u *User) ChangeUSDBalance(action domain2.USDAction, amount domain2.USD) error

type UserRepository

type UserRepository interface {
	Create(user *User) error
	Get(id uint64) (*User, error)
	// Update accept id of user, get it and pass in updFunc.
	// updFunc should update the user and return the updated user
	Update(
		id uint64, updFunc func(*User) (*User, error),
	) error
	Delete(id uint64) error
}

Jump to

Keyboard shortcuts

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