model

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultsPerPage    = 10.0
	MaxPagesNavigator = 5
)
View Source
const (
	RoleRegular = iota + 1
	RoleAdmin
)

User roles identifiers

View Source
const UsernamePattern = `^[A-z0-9_\-.]+$`

Variables

This section is empty.

Functions

func Hash

func Hash(s string) string

func Paginate

func Paginate(currentPage int, pageSize int) func(db *gorm.DB) *gorm.DB

Types

type Highlight

type Highlight struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	UserID    int    `gorm:"primaryKey"`
	Path      string `gorm:"primaryKey"`
}

type HighlightRepository

type HighlightRepository struct {
	DB *gorm.DB
}

func (*HighlightRepository) Highlight

func (u *HighlightRepository) Highlight(userID int, documentPath string) error

func (*HighlightRepository) Highlighted

func (u *HighlightRepository) Highlighted(userID int, doc index.Document) index.Document

func (*HighlightRepository) HighlightedPaginatedResult

func (u *HighlightRepository) HighlightedPaginatedResult(userID int, results result.Paginated[[]index.Document]) result.Paginated[[]index.Document]

func (*HighlightRepository) Highlights

func (u *HighlightRepository) Highlights(userID int, page int, resultsPerPage int) (result.Paginated[[]string], error)

func (*HighlightRepository) Remove

func (u *HighlightRepository) Remove(userID int, documentPath string) error

func (*HighlightRepository) RemoveDocument

func (u *HighlightRepository) RemoveDocument(documentPath string) error

type Session

type Session struct {
	User
	Exp float64
}

type User

type User struct {
	ID                 uint `gorm:"primarykey"`
	CreatedAt          time.Time
	UpdatedAt          time.Time
	Uuid               string `gorm:"uniqueIndex; not null"`
	Name               string `gorm:"not null"`
	Username           string `gorm:"type:text collate nocase; not null; unique"`
	Email              string `gorm:"uniqueIndex; not null"`
	SendToEmail        string
	Password           string
	Role               int `gorm:"not null"`
	WordsPerMinute     float64
	RecoveryUUID       string
	RecoveryValidUntil time.Time
	Highlights         []Highlight `gorm:"constraint:OnDelete:CASCADE"`
}

func (User) ConfirmPassword

func (u User) ConfirmPassword(confirmPassword string, minPasswordLength int, errs map[string]string) map[string]string

func (User) Validate

func (u User) Validate(minPasswordLength int) map[string]string

Validate checks all user's fields to ensure they are in the required format

type UserRepository

type UserRepository struct {
	DB *gorm.DB
}

func (*UserRepository) Admins

func (u *UserRepository) Admins() int64

func (*UserRepository) Create

func (u *UserRepository) Create(user *User) error

func (*UserRepository) Delete

func (u *UserRepository) Delete(uuid string) error

func (*UserRepository) FindByEmail

func (u *UserRepository) FindByEmail(email string) (*User, error)

func (*UserRepository) FindByRecoveryUuid

func (u *UserRepository) FindByRecoveryUuid(recoveryUuid string) (*User, error)

func (*UserRepository) FindByUsername

func (u *UserRepository) FindByUsername(username string) (*User, error)

func (*UserRepository) FindByUuid

func (u *UserRepository) FindByUuid(uuid string) (*User, error)

func (*UserRepository) List

func (u *UserRepository) List(page int, resultsPerPage int) (result.Paginated[[]User], error)

func (*UserRepository) Total

func (u *UserRepository) Total() int64

func (*UserRepository) Update

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

Jump to

Keyboard shortcuts

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