entity

package
v0.0.0-...-fbd1cd9 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsComment

func ContainsComment(comments []Comment, targetID uint) bool

func ContainsCookedComment

func ContainsCookedComment(comments []CookedComment, targetID uint) bool

Types

type Artran

type Artran struct {
	ID  string `json:"id"`
	Rid string `json:"rid"`

	Content string `json:"content"`

	UA          string `json:"ua"`
	IP          string `json:"ip"`
	IsCollapsed string `json:"is_collapsed"` // bool => string "true" or "false"
	IsPending   string `json:"is_pending"`   // bool
	IsPinned    string `json:"is_pinned"`    // bool

	// vote
	VoteUp   string `json:"vote_up"`
	VoteDown string `json:"vote_down"`

	// date
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`

	// user
	Nick       string `json:"nick"`
	Email      string `json:"email"`
	Link       string `json:"link"`
	BadgeName  string `json:"badge_name"`
	BadgeColor string `json:"badge_color"`

	// page
	PageKey       string `json:"page_key"`
	PageTitle     string `json:"page_title"`
	PageAdminOnly string `json:"page_admin_only"` // bool

	// site
	SiteName string `json:"site_name"`
	SiteUrls string `json:"site_urls"`
}

数据行囊 (n 个 Artran 组成一个 Artrans) Fields All String type (FAS)

type Comment

type Comment struct {
	gorm.Model

	Content string

	PageKey  string `gorm:"index;size:255"`
	SiteName string `gorm:"index;size:255"`

	UserID     uint `gorm:"index"`
	IsVerified bool `gorm:"default:false"`
	UA         string
	IP         string

	Rid uint `gorm:"index"` // Parent Node ID

	IsCollapsed bool `gorm:"default:false"`
	IsPending   bool `gorm:"default:false"`
	IsPinned    bool `gorm:"default:false"`

	VoteUp   int
	VoteDown int

	RootID uint `gorm:"index"` // Root Node ID (can be derived from `Rid`)

	// Associated Page
	//
	// Use Composite Foreign Keys for multiple-site support.
	Page *Page `gorm:"foreignKey:page_key,site_name;references:key,site_name"`

	// Associated User
	User *User `gorm:"foreignKey:user_id;references:id"`
}

func (Comment) IsAllowReply

func (c Comment) IsAllowReply() bool

func (Comment) IsEmpty

func (c Comment) IsEmpty() bool

type CookedComment

type CookedComment struct {
	ID             uint   `json:"id"`
	Content        string `json:"content"`
	ContentMarked  string `json:"content_marked"`
	UserID         uint   `json:"user_id"`
	Nick           string `json:"nick"`
	EmailEncrypted string `json:"email_encrypted"`
	Link           string `json:"link"`
	UA             string `json:"ua"`
	Date           string `json:"date"`
	IsCollapsed    bool   `json:"is_collapsed"`
	IsPending      bool   `json:"is_pending"`
	IsPinned       bool   `json:"is_pinned"`
	IsAllowReply   bool   `json:"is_allow_reply"`
	IsVerified     bool   `json:"is_verified"`
	Rid            uint   `json:"rid"`
	BadgeName      string `json:"badge_name"`
	BadgeColor     string `json:"badge_color"`
	IP             string `json:"-"`
	IPRegion       string `json:"ip_region,omitempty"`
	Visible        bool   `json:"visible"`
	VoteUp         int    `json:"vote_up"`
	VoteDown       int    `json:"vote_down"`
	PageKey        string `json:"page_key"`
	PageURL        string `json:"page_url"`
	SiteName       string `json:"site_name"`
}

type CookedCommentForEmail

type CookedCommentForEmail struct {
	CookedComment
	Content    string     `json:"content"`
	ContentRaw string     `json:"content_raw"`
	Nick       string     `json:"nick"`
	Email      string     `json:"email"`
	IP         string     `json:"ip"`
	Datetime   string     `json:"datetime"`
	Date       string     `json:"date"`
	Time       string     `json:"time"`
	PageKey    string     `json:"page_key"`
	PageTitle  string     `json:"page_title"`
	Page       CookedPage `json:"page"`
	SiteName   string     `json:"site_name"`
	Site       CookedSite `json:"site"`
}

type CookedNotify

type CookedNotify struct {
	ID        uint   `json:"id"`
	UserID    uint   `json:"user_id"`
	CommentID uint   `json:"comment_id"`
	IsRead    bool   `json:"is_read"`
	IsEmailed bool   `json:"is_emailed"`
	ReadLink  string `json:"read_link"`
}

type CookedPage

type CookedPage struct {
	ID        uint   `json:"id"`
	AdminOnly bool   `json:"admin_only"`
	Key       string `json:"key"`
	URL       string `json:"url"`
	Title     string `json:"title"`
	SiteName  string `json:"site_name"`
	VoteUp    int    `json:"vote_up"`
	VoteDown  int    `json:"vote_down"`
	PV        int    `json:"pv"`
}

type CookedSite

type CookedSite struct {
	ID       uint     `json:"id"`
	Name     string   `json:"name"`
	Urls     []string `json:"urls"`
	UrlsRaw  string   `json:"urls_raw"`
	FirstUrl string   `json:"first_url"`
}

type CookedUser

type CookedUser struct {
	ID           uint   `json:"id"`
	Name         string `json:"name"`
	Email        string `json:"email"`
	Link         string `json:"link"`
	BadgeName    string `json:"badge_name"`
	BadgeColor   string `json:"badge_color"`
	IsAdmin      bool   `json:"is_admin"`
	ReceiveEmail bool   `json:"receive_email"`
}

type CookedUserForAdmin

type CookedUserForAdmin struct {
	CookedUser
	LastIP       string `json:"last_ip"`
	LastUA       string `json:"last_ua"`
	IsInConf     bool   `json:"is_in_conf"`
	CommentCount int64  `json:"comment_count"`
}

type Notify

type Notify struct {
	gorm.Model

	UserID    uint `gorm:"index"` // 通知对象 (接收通知的用户 ID)
	CommentID uint `gorm:"index"` // 待查看的评论

	IsRead    bool
	ReadAt    *time.Time
	IsEmailed bool
	EmailAt   *time.Time

	Key string `gorm:"index;size:255"`
}

func (*Notify) GenerateKey

func (n *Notify) GenerateKey()

操作时的验证密钥(判断是否本人操作)

func (Notify) IsEmpty

func (n Notify) IsEmpty() bool

type Page

type Page struct {
	gorm.Model

	// TODO
	// For historical reasons, the naming of this field does not follow best practices.
	// Keywords should be avoided in naming, and "key" should be changed to a different name.
	Key string `gorm:"index;size:255"` // Page key

	Title     string
	AdminOnly bool

	SiteName string `gorm:"index;size:255"`

	AccessibleURL string `gorm:"-"`

	VoteUp   int
	VoteDown int

	PV int

	Site *Site `gorm:"foreignKey:site_name;references:name"`
}

func (Page) IsEmpty

func (p Page) IsEmpty() bool

type Site

type Site struct {
	gorm.Model
	Name string `gorm:"uniqueIndex;size:255"`
	Urls string
}

func (Site) IsEmpty

func (s Site) IsEmpty() bool

type User

type User struct {
	gorm.Model
	Name           string `gorm:"index;size:255"`
	Email          string `gorm:"index;size:255"`
	Link           string
	Password       string
	BadgeName      string
	BadgeColor     string
	LastIP         string
	LastUA         string
	IsAdmin        bool
	ReceiveEmail   bool `gorm:"default:true"`
	TokenValidFrom sql.NullTime

	// 配置文件中添加的
	IsInConf bool
}

func (*User) CheckPassword

func (u *User) CheckPassword(input string) bool

func (User) IsEmpty

func (u User) IsEmpty() bool

func (*User) SetPasswordEncrypt

func (u *User) SetPasswordEncrypt(password string) (err error)

type Vote

type Vote struct {
	gorm.Model

	TargetID uint     `gorm:"index"` // 投票对象
	Type     VoteType `gorm:"index"`

	UserID uint `gorm:"index"` // 投票者
	UA     string
	IP     string
}

func (*Vote) IsEmpty

func (v *Vote) IsEmpty() bool

func (*Vote) IsUp

func (v *Vote) IsUp() bool

type VoteType

type VoteType string
const (
	VoteTypeCommentUp   VoteType = "comment_up"
	VoteTypeCommentDown VoteType = "comment_down"
	VoteTypePageUp      VoteType = "page_up"
	VoteTypePageDown    VoteType = "page_down"
)

Jump to

Keyboard shortcuts

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