models

package
v0.0.0-...-8ae76b5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 4 Imported by: 0

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 CategoryStorage interface {
	Insert(name string, categoryType CategoryType, userID int64, inactive bool) (int64, error)
	All(userID int64, filters Filters) ([]*Category, Metadata, error)
}

type CategoryType

type CategoryType struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

CategoryType represends a category type: with ID = 1 - income, ID = 2 - expense

type Currency

type Currency struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Unit string `json:"unit"`
}

Currency represents currencies model

type Filters

type Filters struct {
	Page     int
	PageSize int
}

func (Filters) CurrentPage

func (f Filters) CurrentPage() int

func (Filters) Limit

func (f Filters) Limit() int

func (Filters) Offset

func (f Filters) Offset() int

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

func CalculateMetadata(totalRecords, page, pageSize int) Metadata

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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