account

package
v0.0.0-...-5f3b81a Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAccountNotFound is returned when an account doesn't exist
	ErrAccountNotFound error = errors.New("Account not found")

	// ErrAccountExists is returned when an account is attempted to be created, but already exists
	ErrAccountExists error = errors.New("Account already exists")
)
View Source
var (
	ErrUserExists   error = errors.New("User already exists")
	ErrUserNotFound error = errors.New("User not found")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	// Id of this account
	Id uuid.UUID `json:"id" pg:",pk,type:uuid,default:uuid_generate_v4()"`

	CreatorId uuid.UUID `json:"creator_id" pg:"type:uuid,notnull"`
	// Creator is who owns this account, and what the balance is reflective of
	Creator *User `json:"creator"`

	SubjectId uuid.UUID `json:"subject_id" pg:"type:uuid,notnull"`
	// Subject is who this account includes, who is related to it, etc.
	Subject *User `json:"subject"`

	// Balance is the current balance of this account
	Balance float64 `json:"balance" pg:"default:0"`

	// CreatedAt is when this account was created
	CreatedAt time.Time `json:"created_at" pg:"default:now(),notnull"`

	// UpdatedAt is when this account was last updated (any fields modified update this)
	UpdatedAt time.Time `json:"updated_at" pg:"default:now(),notnull"`
}

Account is a user's account

func (*Account) String

func (a *Account) String() string

type Client

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

func NewClient

func NewClient(db *pg.DB) *Client

NewClient creates a new client

func (*Client) CreateAccount

func (c *Client) CreateAccount(a *Account) error

CreateAccount creates an account

func (*Client) CreateTransaction

func (c *Client) CreateTransaction(createdBy *User, involved []User, amount float64) error

CreateUser creates a new transaction in the database

func (*Client) CreateUser

func (c *Client) CreateUser(u *User) error

CreateUser creates a user in the database

func (*Client) FindAccountBetween

func (c *Client) FindAccountBetween(u1 *User, u2 *User) (*Account, error)

FindAccountBetween finds an account between a user

func (*Client) FindAccounts

func (c *Client) FindAccounts(u *User) ([]*Account, error)

FindAccounts finds all accounts owned by a user

func (*Client) FindUser

func (c *Client) FindUser(p PlatformName, id string) (*User, error)

FindUser finds a user by their social ID

func (*Client) FindUserByUsernam

func (c *Client) FindUserByUsernam(p PlatformName, username string) (*User, error)

FindUserByUsername finds a user by their social ID

func (*Client) GetAccount

func (c *Client) GetAccount(id uuid.UUID) (*Account, error)

GetAccount returns an account

func (*Client) GetAllTransactionsByUser

func (c *Client) GetAllTransactionsByUser(u *User, filterUser *User) ([]*Transaction, error)

func (*Client) GetTransaction

func (c *Client) GetTransaction(id string) (*Transaction, error)

GetTransaction by ID

func (*Client) GetUser

func (c *Client) GetUser(id uuid.UUID) (*User, error)

GetUser returns a user

func (*Client) ListUsers

func (c *Client) ListUsers() ([]*User, error)

ListUsers returns a list of all the users in the database

func (*Client) NewTransaction

func (c *Client) NewTransaction(creator *User, subject *User, amount float64) error

NewTransaction records a new transaction

type PlatformName

type PlatformName string
const (
	PlatformTelegram PlatformName = "telegram"
)

type Transaction

type Transaction struct {
	// Id of the User
	Id uuid.UUID `json:"id" pg:",pk,type:uuid,default:uuid_generate_v4()"`

	// CreatedBy is the user who created this transaction
	CreatedBy uuid.UUID `pg:"created_by,type:uuid" json:"created_by"`

	// Account is a userID -> accountID mapping of accounts that
	// were hit during this transaction
	Accounts map[uuid.UUID]uuid.UUID `pg:"accounts" json:"account_id"`

	// Amount that this transaction was for, split across all involved users
	Amount float64 `json:"amount" pg:"amount"`

	CreatedAt time.Time `json:"created_at" pg:"default:now(),notnull"`
}

Transaction is a user transaction

func (*Transaction) String

func (t *Transaction) String() string

type User

type User struct {
	// Id of the User
	Id uuid.UUID `json:"id" pg:",pk,type:uuid,default:uuid_generate_v4()"`

	// PlatformIds are IDs on various platforms this user belongs in
	PlatformIds       map[PlatformName]string `pg:"platform_ids,notnull" json:"platform_ids"`
	PlatformUsernames map[PlatformName]string `pg:"platform_usernames,notnull" json:"platform_usernames"`

	CreatedAt time.Time `json:"created_at" pg:"default:now(),notnull"`
	UpdatedAt time.Time `json:"updated_at" pg:"default:now(),notnull"`
}

User is an account owner

func (*User) String

func (u *User) String() string

Jump to

Keyboard shortcuts

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