models

package
v0.0.0-...-5b45539 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPageStatusIsInvalid page status is invalid
	ErrPageStatusIsInvalid = errors.New("page status is invalid")
)
View Source
var (
	// ErrSpaceStatusIsInvalid space status is invalid
	ErrSpaceStatusIsInvalid = errors.New("space status is invalid")
)

Functions

func Migrate

func Migrate(db *database.Database) error

Migrate models

Types

type Account

type Account struct {
	database.Model
	Login    string     `json:"login"    gorm:"uniqueIndex;size:255"`
	Email    string     `json:"email"    gorm:"uniqueIndex;size:255"`
	Name     string     `json:"name"     gorm:"size:255"`
	Bio      string     `json:"bio"      gorm:"size:255"`
	Location string     `json:"location" gorm:"size:255"`
	Status   UserStatus `json:"status"   gorm:"size:32"`

	Authentication *Authentication `json:"-"`
	Avatar         string          `json:"avatar" gorm:"-"`
}

Account model

func (*Account) AfterFind

func (account *Account) AfterFind(tx *gorm.DB) (err error)

AfterFind gorm after find callback

func (*Account) BeforeDelete

func (account *Account) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete gorm before delete callback

func (Account) TableName

func (Account) TableName() string

TableName user model table name

type Authentication

type Authentication struct {
	ID                int64  `gorm:"primaryKey"`
	AccountID         int64  `gorm:"uniqueIndex"`                            // Account ID
	Password          string `json:"-"                  gorm:"-"`            // Password
	EncryptedPassword []byte `json:"-"                  gorm:"default:NULL"` // Encrypted password
	CurrentSignInAt   int64  `json:"current_sign_in_at"`                     // Current sign in time
	CurrentSignInIP   string `json:"current_sign_in_ip" gorm:"size:255"`     // Current sign in ip
	LastSignInAt      int64  `json:"last_sign_in_at"`                        // Last sign in time
	LastSignInIP      string `json:"last_sign_in_ip"    gorm:"size:255"`     // Last sign in ip
	FailedAttempts    int    `json:"failed_attempts"`                        // Failed attempt count
	UnlockToken       []byte `json:"unlock_token"       gorm:"default:NULL"` // Lock token
	LockedAt          int64  `json:"locked_at"`                              // Lock at time
	ResetToken        []byte `json:"reset_token"        gorm:"default:NULL"` // Reset token
	ResetAt           int64  `json:"reset_at"`                               // Reset at time
}

Authentication model

func (*Authentication) BeforeCreate

func (auth *Authentication) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate gorm before create callback

func (Authentication) TableName

func (Authentication) TableName() string

TableName user model table name

type Page

type Page struct {
	ID            int64         `json:"id"             nestedset:"id"             gorm:"primaryKey;autoIncrement"`
	ParentID      sql.NullInt64 `json:"parent_id"      nestedset:"parent_id"      gorm:"index"`
	Lft           int           `json:"-"              nestedset:"lft"`
	Rgt           int           `json:"-"              nestedset:"rgt"`
	Depth         int           `json:"-"              nestedset:"depth"`
	ChildrenCount int           `json:"children_count" nestedset:"children_count"`
	SpaceID       int64         `json:"-"              nestedset:"scope"          gorm:"index"`

	Space           *Space       `json:"space,omitempty"`
	Content         *PageContent `json:"-"`
	FallbackContent *PageContent `json:"-"`

	Children []*Page `json:"children,omitempty" gorm:"-"`
	Parents  []*Page `json:"parents,omitempty"  gorm:"-"`
}

Page page meta model

func (*Page) AfterFind

func (page *Page) AfterFind(tx *gorm.DB) error

AfterFind gorm after find callback

func (*Page) MarshalJSON

func (page *Page) MarshalJSON() ([]byte, error)

MarshalJSON implement

func (Page) TableName

func (Page) TableName() string

TableName user model table name

type PageContent

type PageContent struct {
	ID int64 `json:"-" gorm:"primaryKey"`

	SpaceID   int64 `json:"-" gorm:"index"`
	CreatorID int64 `json:"-" gorm:"index"`

	PageID  int64  `json:"-"       gorm:"uniqueIndex:page_content"`
	Lang    string `json:"lang"    gorm:"uniqueIndex:page_content;size:32"`
	Version string `json:"version" gorm:"uniqueIndex:page_content;size:64"`

	Status     PageStatus `json:"status"      gorm:"size:32"`
	Title      string     `json:"title"       gorm:"size:255;index"`
	ShortTitle string     `json:"short_title" gorm:"size:255;index"`
	Body       string     `json:"body"`
	HTML       string     `json:"html"`

	CreatedAt int64                 `json:"created_at"`
	UpdatedAt int64                 `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`

	Space *Space `json:"space,omitempty"`
	Page  *Page  `json:"page,omitempty"`
}

PageContent page version model

func (PageContent) TableName

func (PageContent) TableName() string

TableName user model table name

func (*PageContent) Text

func (page *PageContent) Text() string

Text html plain text

type PageQuery

type PageQuery struct {
	Lang    string
	Version string
}

PageQuery page unique keys

type PageStatus

type PageStatus string

PageStatus page status

const (
	PageStatusDraft      PageStatus = "draft"
	PageStatusPublished  PageStatus = "published"
	PageStatusOffline    PageStatus = "offline"
	PageStatusDeprecated PageStatus = "deprecated"
)

PageStatus enum

func (PageStatus) IsValid

func (t PageStatus) IsValid() error

IsValid return space status is valid

type Pages

type Pages []*Page

Pages pages type

func (*Pages) Build

func (nodes *Pages) Build() Pages

Build tree

type Revision

type Revision struct {
	ID        int64 `json:"id"         gorm:"primaryKey"`
	CreatedAt int64 `json:"created_at"`
	UpdatedAt int64 `json:"updated_at"`

	OwnerID   int64  `json:"owner_id"`
	OwnerType string `json:"owner_type"`
}

Revision model

type Space

type Space struct {
	database.Model
	Name         string      `json:"name"          gorm:"uniqueIndex;size:128"`
	Key          string      `json:"key"           gorm:"uniqueIndex;size:128"`
	Multilingual bool        `json:"multilingual"`                 // Enable multilingual
	Lang         string      `json:"lang"          gorm:"size:32"` // default lang // TODO(m) enum type
	FallbackLang string      `json:"fallback_lang" gorm:"size:32"` // fallback lang
	HomepageID   int64       `json:"homepage_id"   gorm:"index"`
	Description  string      `json:"description"`
	Avatar       string      `json:"avatar"`
	Status       SpaceStatus `json:"status"        gorm:"index;size:32"`
	CreatorID    int64       `json:"-"`

	Homepage *Page `json:"homepage,omitempty" gorm:"foreignKey:HomepageID"`

	// TODO(m) rename to Homepage
	HomepageContent         *PageContent `json:"-" gorm:"foreignKey:HomepageID;references:PageID"`
	HomepageFallbackContent *PageContent `json:"-" gorm:"foreignKey:HomepageID;references:PageID"`
}

Space model

func (*Space) AfterFind

func (space *Space) AfterFind(tx *gorm.DB) error

AfterFind gorm after find callback

func (*Space) BeforeDelete

func (space *Space) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete gorm before delete callback

func (Space) TableName

func (Space) TableName() string

TableName user model table name

type SpaceStatus

type SpaceStatus string

SpaceStatus space status

const (
	SpaceStatusOffline SpaceStatus = "offline"
	SpaceStatusOnline  SpaceStatus = "online"
)

SpaceStatus enum

func (SpaceStatus) IsValid

func (t SpaceStatus) IsValid() error

IsValid return space status is valid

type UserStatus

type UserStatus string

UserStatus user status

const (
	UserPendingStatus   UserStatus = "pending"
	UserActivatedStatus UserStatus = "activated"
	UserDisabledStatus  UserStatus = "disabled"
)

UserStatus enum

func (UserStatus) IsValid

func (status UserStatus) IsValid() bool

IsValid 是否有效

type Version

type Version struct {
	ID      int64  `json:"id"       gorm:"primaryKey"`
	SpaceID int64  `json:"space_id" gorm:"uniqueIndex:space_version"`
	Name    string `json:"name"     gorm:"uniqueIndex:space_version"`

	CreatedAt int64                 `json:"created_at"`
	UpdatedAt int64                 `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}

Version model

Jump to

Keyboard shortcuts

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