data

package
v0.0.0-...-1f349b9 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
	ErrEditConflict   = errors.New("edit conflict")
)
View Source
var AnonymousUser = &User{}
View Source
var (
	ErrDuplicateEmail = errors.New("duplicate email")
)

Functions

func ValidateEmail

func ValidateEmail(v *validator.Validator, email string)

func ValidatePassword

func ValidatePassword(v *validator.Validator, plaintext string)

func ValidateTokenPlaintext

func ValidateTokenPlaintext(v *validator.Validator, plaintext string)

func ValidateUser

func ValidateUser(v *validator.Validator, user *User)

Types

type Expense

type Expense struct {
	ID          int64
	UserID      int64
	Date        time.Time
	Recipient   string
	Description string
	Category    string
	Value       *money.Money
	Version     int
}

type ExpenseModel

type ExpenseModel struct {
	DB *sql.DB
}

func (ExpenseModel) GetAll

func (m ExpenseModel) GetAll(recipient string, month time.Time, category string, filters Filters) ([]*Expense, error)

func (ExpenseModel) Insert

func (m ExpenseModel) Insert(expense *Expense) error

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafelist []string
}

type Models

type Models struct {
	Users interface {
		Insert(user *User) error
		GetByEmail(email string) (*User, error)
		Update(user *User) error
		GetForToken(scope string, plaintext string) (*User, error)
	}
	Tokens interface {
		New(userID int64, ttl time.Duration, scope string) (*Token, error)
		Insert(token *Token) error
		DeleteAllForUser(scope string, userID int64) error
	}
}

func NewModels

func NewModels(db *sql.DB) Models

type Token

type Token struct {
	UserID    int64     `json:"-"`
	Plaintext string    `json:"token"`
	Hash      []byte    `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-"`
}

type TokenModel

type TokenModel struct {
	DB *sql.DB
}

func (TokenModel) DeleteAllForUser

func (m TokenModel) DeleteAllForUser(scope string, userID int64) error

func (TokenModel) Insert

func (m TokenModel) Insert(token *Token) error

func (TokenModel) New

func (m TokenModel) New(userID int64, ttl time.Duration, scope string) (*Token, error)

type User

type User struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	Email     string    `json:"email"`
	Password  password  `json:"-"`
	Version   int       `json:"-"`
	Activated bool      `json:"activated"`
	CreatedAt time.Time `json:"created_at"`
}

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (UserModel) GetByEmail

func (m UserModel) GetByEmail(email string) (*User, error)

func (UserModel) GetForToken

func (m UserModel) GetForToken(scope string, tokenPlaintext string) (*User, error)

func (UserModel) Insert

func (m UserModel) Insert(user *User) error

func (UserModel) Update

func (m UserModel) Update(user *User) error

Jump to

Keyboard shortcuts

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