Documentation
¶
Overview ¶
Package bet provides an example of a core business API. Right now these calls are just wrapping the data/store layer. But at some point you will want to audit or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type Account
- type Bet
- type Core
- func (c Core) CreateAccount(ctx context.Context, na NewAccount) (Account, error)
- func (c Core) CreateBet(ctx context.Context, nb NewBet, now time.Time) (Bet, error)
- func (c Core) QueryBet(ctx context.Context, pageNumber int, rowsPerPage int) ([]Bet, error)
- func (c Core) QueryBetByID(ctx context.Context, betID string) (Bet, error)
- func (c Core) UpdateAccount(ctx context.Context, address string, ua UpdateAccount) error
- func (c Core) UpdateBet(ctx context.Context, betID string, uBet UpdateBet, now time.Time) error
- type NewAccount
- type NewBet
- type NewPlayer
- type Player
- type UpdateAccount
- type UpdateBet
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("account not found") ErrInvalidAddress = errors.New("address is not in its proper form") ErrInvalidNonce = errors.New("nonce must be 1 greater than previous nonce") ErrInvalidID = errors.New("ID is not in its proper form") )
Set of error variables for CRUD operations.
Functions ¶
This section is empty.
Types ¶
type Bet ¶
type Bet struct { ID string `json:"id"` Status string `json:"status"` Description string `json:"description"` Terms string `json:"terms"` Amount int `json:"amount"` ModeratorAddress string `json:"moderatorAddress"` Players []Player `json:"players"` DateExpired time.Time `json:"dateExpired"` DateCreated time.Time `json:"dateCreated"` DateUpdated time.Time `json:"dateUpdated"` }
Bet represents an individual bet.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for product access.
func NewCore ¶
func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core
NewCore constructs a core for product api access.
func (Core) CreateAccount ¶
CreateAccount adds an Account to the database. It returns the created Account with fields populated.
func (Core) QueryBetByID ¶
QueryBetByID finds the bet identified by a given ID.
func (Core) UpdateAccount ¶
UpdateAccount modifies data about an Account. It will error if the specified address is invalid or does not reference an existing Account.
type NewAccount ¶
type NewAccount struct {
Address string `json:"address"`
}
NewAccount contains information needed to create a new Account.
type NewBet ¶
type NewBet struct { Description string `json:"description"` Terms string `json:"terms"` Amount int `json:"amount"` ModeratorAddress string `json:"moderatorAddress"` Players []NewPlayer `json:"players" validate:"required"` DateExpired time.Time `json:"dateExpired"` }
NewBet is what we require from clients when adding a Bet.
type NewPlayer ¶
NewPlayer represents the connection between a new Bet and an Account that is in a player role.
type Player ¶
type Player struct { BetID string `db:"betId"` Address string `db:"address"` InFavor bool `db:"inFavor"` }
Player represents the connection between a Bet and an Account that is in a player role.
type UpdateAccount ¶
UpdateAccount contains information needed to update an Account.