data

package
v0.0.0-...-32ec16d Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

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")
View Source
var ErrInvalidRoasterID = errors.New("invalid roaster id")

Functions

func ValidateEmail

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

func ValidatePasswordPlaintext

func ValidatePasswordPlaintext(v *validator.Validator, password string)

Types

type Bean

type Bean struct {
	ID         int64
	Name       string
	RoastLevel string
	RoasterID  int64
	CreatedAt  time.Time
	Version    int
}

func (*Bean) Validate

func (b *Bean) Validate(v *validator.Validator)

type BeanRepository

type BeanRepository struct {
	DB *sql.DB
}

func (BeanRepository) Delete

func (rep BeanRepository) Delete(id int64) error

func (BeanRepository) Get

func (rep BeanRepository) Get(id int64) (*Bean, error)

func (BeanRepository) GetAll

func (rep BeanRepository) GetAll() ([]*Bean, error)

func (BeanRepository) GetAllForRoaster

func (rep BeanRepository) GetAllForRoaster(roasterID int64) ([]*Bean, error)

func (BeanRepository) Insert

func (rep BeanRepository) Insert(bean *Bean) error

func (BeanRepository) Search

func (rep BeanRepository) Search(sq SearchQuery) ([]*Bean, error)

func (BeanRepository) Update

func (rep BeanRepository) Update(bean *Bean) error

type NullableBean

type NullableBean struct {
	ID         sql.NullInt64
	Name       sql.NullString
	RoastLevel sql.NullString
	RoasterID  sql.NullInt64
	CreatedAt  sql.NullTime
	Version    sql.NullInt32
}

func (NullableBean) UnNullify

func (nb NullableBean) UnNullify() Bean

type PermissionRepository

type PermissionRepository struct {
	DB *sql.DB
}

func (PermissionRepository) AddForUser

func (rep PermissionRepository) AddForUser(userID int64, codes ...string) error

func (PermissionRepository) GetAllForUser

func (rep PermissionRepository) GetAllForUser(userID int64) (Permissions, error)

type Permissions

type Permissions []string

func (Permissions) Contains

func (p Permissions) Contains(code string) bool

type Repositories

type Repositories struct {
	Beans       BeanRepository
	Permissions PermissionRepository
	Roasters    RoasterRepository
	Users       UserRepository
}

func NewRepositories

func NewRepositories(db *sql.DB) Repositories

type Roaster

type Roaster struct {
	ID          int64
	Name        string
	Description string
	Website     string
	Location    string
	Beans       []*Bean
	CreatedAt   time.Time
	Version     int
}

func (*Roaster) Validate

func (r *Roaster) Validate(v *validator.Validator)

type RoasterRepository

type RoasterRepository struct {
	DB *sql.DB
}

func (RoasterRepository) Delete

func (rep RoasterRepository) Delete(id int64) error

func (RoasterRepository) Get

func (rep RoasterRepository) Get(id int64) (*Roaster, error)

func (RoasterRepository) GetAllFull

func (rep RoasterRepository) GetAllFull() ([]*Roaster, error)

func (RoasterRepository) GetFull

func (rep RoasterRepository) GetFull(id int64) (*Roaster, error)

func (RoasterRepository) Insert

func (rep RoasterRepository) Insert(roaster *Roaster) error

func (RoasterRepository) Search

func (rep RoasterRepository) Search(sq SearchQuery) ([]*Roaster, error)

func (RoasterRepository) Update

func (rep RoasterRepository) Update(roaster *Roaster) error

type SearchQuery

type SearchQuery struct {
	Term            string
	Sort            string
	SortableColumns []string // TODO: change to hashset?
}

func (SearchQuery) Validate

func (sq SearchQuery) Validate(v *validator.Validator)

type User

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

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

func (*User) Validate

func (u *User) Validate(v *validator.Validator)

type UserRepository

type UserRepository struct {
	DB *sql.DB
}

func (*UserRepository) Exists

func (rep *UserRepository) Exists(id int64) (bool, error)

func (*UserRepository) Get

func (rep *UserRepository) Get(id int64) (*User, error)

func (*UserRepository) GetByEmail

func (rep *UserRepository) GetByEmail(email string) (*User, error)

func (*UserRepository) Insert

func (rep *UserRepository) Insert(user *User) error

func (*UserRepository) Update

func (rep *UserRepository) Update(user *User) error

Jump to

Keyboard shortcuts

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