Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrDuplicateEmail received when user with the same email already exists ErrDuplicateEmail = errors.New("models: duplicate email") // ErrDuplicateToken received when auth_session with the same token already exists ErrDuplicateToken = errors.New("models: duplicate token") // ErrNoRecord received when the record not found in the database ErrNoRecord = errors.New("models: record not found") // ErrWrongPassword recived when the password is incorrect ErrWrongPassword = errors.New("users: wrong password") // ErrUserNotConfirmed received when user is not confirmed ErrUserNotConfirmed = errors.New("users: not confirmed") )
View Source
var AnonymousSession = &AuthSession{}
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { ID int64 `json:"id"` Name string `json:"name"` Balance float64 `json:"balance"` Currency Currency `json:"currency"` Status string `json:"status"` ShowInSummary bool `json:"show_in_summary"` UserID int64 `json:"-"` }
Account represents a user's accounts
type AccountStorage ¶
type AccountStorage interface { Insert(name string, userID int64, currencyID int64, status string, showInSummary bool) (int64, error) All(userID int64, filters Filters) ([]*Account, Metadata, error) }
AccountStorate contains information about user's accounts
type AuthSession ¶
type AuthSession struct { ID int64 UserID int64 Token string ExpiredAt *time.Time CreatedAt *time.Time UpdatedAt *time.Time }
AuthSession represents authentication session data
func (*AuthSession) IsAnonymous ¶
func (s *AuthSession) IsAnonymous() bool
type AuthSessionStorage ¶
type AuthSessionStorage interface { Insert(userID int64, token string) (int64, error) Get(id int64) (*AuthSession, error) GetByToken(token string) (*AuthSession, error) Delete(id int64) error }
AuthSessionStorage contains information about current API authentications
type Category ¶
type Category struct { ID int64 `json:"id"` Name string `json:"name"` CategoryType CategoryType `json:"category_type"` UserID int64 `json:"-"` Inactive bool `json:"inactive"` UpdatedAt *time.Time `json:"-"` }
Category represents an expense category
type CategoryStorage ¶
type CategoryType ¶
CategoryType represends a category type: with ID = 1 - income, ID = 2 - expense
type Filters ¶
func (Filters) CurrentPage ¶
type Metadata ¶
type Metadata struct { CurrentPage int `json:"current_page,omitempty"` PageSize int `json:"page_size,omitempty"` FirstPage int `json:"first_page,omitempty"` LastPage int `json:"last_page,omitempty"` TotalRecords int `json:"total_records,omitempty"` }
func CalculateMetadata ¶
type Models ¶
type Models struct { Accounts AccountStorage AuthSessions AuthSessionStorage Categories CategoryStorage Users UserStorage Transactions TransactionStorage }
type Transaction ¶
type Transaction struct { ID int64 `json:"id"` Amount float64 `json:"amount"` Comment string `json:"comment"` UserID int64 `json:"-"` Category Category `json:"category"` Account Account `json:"account"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"-"` }
Transaction represents transactions model
type TransactionStorage ¶
type TransactionStorage interface { Insert(amount float64, comment string, userID, categoryID, accountID int64) (int64, error) All(userID int64, filters Filters) ([]*Transaction, Metadata, error) }
TransactionStorage defined interface for storing and retrieving transations data
type User ¶
type User struct { ID int64 Email string EncryptedPassword []byte CreatedAt *time.Time UpdatedAt *time.Time ConfirmedAt mysql.NullTime // https://medium.com/aubergine-solutions/how-i-handled-null-possible-values-from-database-rows-in-golang-521fb0ee267 }
User represents a user data
type UserStorage ¶
type UserStorage interface { Authenticate(email, password string) (string, error) Confirm(id int64) error Get(id int64) (*User, error) GetByEmail(email string) (*User, error) Insert(email, password string) (int64, error) Delete(id int64) error }
UserStorage defines interface to storing and retrieving user data
Click to show internal directories.
Click to hide internal directories.