model

package
v4.19.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: GPL-3.0 Imports: 13 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 Highlight

type Highlight struct {
	CreatedAt  time.Time
	UpdatedAt  time.Time
	UserID     int    `gorm:"primaryKey;index;not null"`
	Path       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
}

func (*HighlightRepository) Highlight

func (u *HighlightRepository) Highlight(userID int, documentPath 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[[]Highlight], error)

func (*HighlightRepository) Remove

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

func (*HighlightRepository) RemoveDocument

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

func (*HighlightRepository) Share added in v4.19.0

func (u *HighlightRepository) Share(senderID int, documentID, 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"`
	Path        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
}

func (*ReadingRepository) CompletedBetweenDates added in v4.15.0

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

CompletedBetweenDates returns paths 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, documentID string) (*time.Time, error)

func (*ReadingRepository) CompletedPaginatedResult added in v4.15.0

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

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, documentPath 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(documentPath string) error

func (*ReadingRepository) Touch added in v4.14.0

func (u *ReadingRepository) Touch(userID int, documentPath 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, documentPath, position string) error

func (*ReadingRepository) UpdateCompletionDate added in v4.15.0

func (u *ReadingRepository) UpdateCompletionDate(userID int, documentPath 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