model

package
v4.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: GPL-3.0 Imports: 15 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

View Source
var AllowedDefaultActions = []string{"download", "send", "share", "copy"}

Functions

func AugmentedDocumentsFromDocuments added in v4.19.0

func AugmentedDocumentsFromDocuments(results result.Paginated[[]index.Document]) result.Paginated[[]AugmentedDocument]

func Hash

func Hash(s string) string

func Paginate

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

Types

type AugmentedDocument added in v4.19.0

type AugmentedDocument struct {
	index.Document
	Highlight   Highlight
	CompletedOn *time.Time
}

type CompletedYearStats added in v4.21.0

type CompletedYearStats struct {
	Year          int
	DocumentCount int
	ReadingTime   string // estimated reading time (e.g. "2h 30m") from word count and user's words-per-minute
}

CompletedYearStats holds aggregated stats for documents completed in a year (or all time when Year is 0).

type Highlight

type Highlight struct {
	CreatedAt  time.Time
	UpdatedAt  time.Time
	UserID     int    `gorm:"primaryKey;index;not null"`
	Slug       string `gorm:"primaryKey;index;not null"`
	SharedByID *int   `gorm:"index"`
	Comment    string `gorm:"type:text"`
	SharedBy   *User  `gorm:"foreignKey:SharedByID"`
}

type HighlightRepository

type HighlightRepository struct {
	DB  *gorm.DB
	Idx idxReader
}

func (*HighlightRepository) Highlight

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

func (*HighlightRepository) Highlighted

func (u *HighlightRepository) Highlighted(userID int, doc AugmentedDocument) AugmentedDocument

func (*HighlightRepository) HighlightedPaginatedResult

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

func (*HighlightRepository) Highlights

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

Highlights returns paginated highlights as AugmentedDocuments (index-backed). Rows whose documents are missing from the index are omitted from Hits() but still count toward TotalHits.

func (*HighlightRepository) Remove

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

func (*HighlightRepository) RemoveDocument

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

func (*HighlightRepository) Share added in v4.19.0

func (u *HighlightRepository) Share(senderID int, documentSlug, comment string, recipientIDs []int) error

func (*HighlightRepository) Total added in v4.19.0

func (u *HighlightRepository) Total(userID int) (int, error)

type Invitation added in v4.15.0

type Invitation struct {
	ID         uint   `gorm:"primarykey"`
	Email      string `gorm:"uniqueIndex; not null"`
	UUID       string `gorm:"uniqueIndex; not null"`
	ValidUntil time.Time
}

Invitation represents a user invitation

type InvitationRepository added in v4.15.0

type InvitationRepository struct {
	DB *gorm.DB
}

func (*InvitationRepository) Create added in v4.15.0

func (i *InvitationRepository) Create(invitation *Invitation) error

func (*InvitationRepository) DeleteByEmail added in v4.15.0

func (i *InvitationRepository) DeleteByEmail(email string) error

func (*InvitationRepository) FindByUUID added in v4.15.0

func (i *InvitationRepository) FindByUUID(uuid string) (*Invitation, error)

type Reading added in v4.9.0

type Reading struct {
	CreatedAt   time.Time  `gorm:"autoCreateTime"`
	UpdatedAt   time.Time  `gorm:"autoUpdateTime"`
	UserID      int        `gorm:"primaryKey"`
	Slug        string     `gorm:"primaryKey"`
	Position    string     `gorm:"type:text"`
	CompletedOn *time.Time `gorm:"default:null"`
}

type ReadingRepository added in v4.9.0

type ReadingRepository struct {
	DB  *gorm.DB
	Idx idxReader
}

func (*ReadingRepository) CompletedBetweenDates added in v4.15.0

func (u *ReadingRepository) CompletedBetweenDates(userID int, startDate, endDate *time.Time) ([]string, error)

CompletedBetweenDates returns slugs of all readings completed by a user. If startDate and endDate are provided, it filters readings completed between those dates (inclusive). If startDate or endDate are nil, they are not used as filters.

func (*ReadingRepository) CompletedOn added in v4.19.0

func (u *ReadingRepository) CompletedOn(userID int, documentSlug string) (*time.Time, error)

func (*ReadingRepository) CompletedPaginatedBetweenDates added in v4.21.0

func (u *ReadingRepository) CompletedPaginatedBetweenDates(userID int, startDate, endDate *time.Time, page int, resultsPerPage int, orderBy string) (result.Paginated[[]AugmentedDocument], error)

CompletedPaginatedBetweenDates returns paginated completed readings for a user as AugmentedDocuments, optionally filtered by date range (inclusive). When startDate and endDate are both nil, all completed readings are returned. orderBy is e.g. "completed_on DESC" or "completed_on ASC"; if empty, "completed_on DESC" is used. Requires Idx to be set; documents missing from the index are skipped from the page but total count is the DB count.

func (*ReadingRepository) CompletedPaginatedResult added in v4.15.0

func (u *ReadingRepository) CompletedPaginatedResult(userID int, results result.Paginated[[]AugmentedDocument]) result.Paginated[[]AugmentedDocument]

func (*ReadingRepository) CompletedStatsByYear added in v4.21.0

func (u *ReadingRepository) CompletedStatsByYear(userID int, wordsPerMinute float64) ([]CompletedYearStats, error)

CompletedStatsByYear returns aggregated stats per year (and "all time" as year 0) including estimated reading time. wordsPerMinute is used to compute ReadingTime for each year. Requires Idx (TotalWordCount) to be set.

func (*ReadingRepository) CompletedYears added in v4.18.1

func (u *ReadingRepository) CompletedYears(userID uint) ([]int, error)

CompletedYears returns the years with completed readings for a user.

func (*ReadingRepository) Get added in v4.14.0

func (u *ReadingRepository) Get(userID int, documentSlug string) (Reading, error)

func (*ReadingRepository) Latest added in v4.9.0

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

func (*ReadingRepository) RemoveDocument added in v4.9.0

func (u *ReadingRepository) RemoveDocument(documentSlug string) error

func (*ReadingRepository) Touch added in v4.14.0

func (u *ReadingRepository) Touch(userID int, documentSlug string) error

Touch creates a reading record if it doesn't exist, but doesn't update it if it does. This is used to track that a document has been opened without overwriting existing positions. Sets updated_at to NULL initially - it will only be set when the reading position is actually updated.

func (*ReadingRepository) Update added in v4.9.0

func (u *ReadingRepository) Update(userID int, documentSlug, position string) error

func (*ReadingRepository) UpdateCompletionDate added in v4.15.0

func (u *ReadingRepository) UpdateCompletionDate(userID int, documentSlug string, completedAt *time.Time) 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"`
	Readings           []Reading   `gorm:"constraint:OnDelete:CASCADE"`
	LastRequest        time.Time
	ShowFileName       bool   `gorm:"default:false; not null"`
	PrivateProfile     int    `gorm:"default:0; not null"`
	PreferredEpubType  string `gorm:"default:'epub'; not null"`
	DefaultAction      string `gorm:"default:'download'; not null"`
	Language           string
}

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, filter string) (result.Paginated[[]User], error)

func (*UserRepository) Total

func (u *UserRepository) Total(filter string) int64

func (*UserRepository) Update

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

func (*UserRepository) UpdateLastRequest added in v4.17.0

func (u *UserRepository) UpdateLastRequest(userID uint) error

func (*UserRepository) UsernamesAndNames added in v4.19.0

func (u *UserRepository) UsernamesAndNames(filter string) ([]User, error)

Jump to

Keyboard shortcuts

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