model

package
v0.0.0-...-c285f8c Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 未激活
	STATUS_NOT_ACTIVE = iota
	// 申请中
	STATUS_APPLYING
	// 激活
	STATUS_ACTIVE
	// 禁用
	STATUS_BANNED
)

Variables

View Source
var DB *gorm.DB

Functions

func AddArticle

func AddArticle(article *Article) error

AddArticle 添加 Article

func AddArticles

func AddArticles(articles []*Article) error

AddArticles 批量添加 Articles

func AddRepo

func AddRepo(repo *Repo) error

func AddTag

func AddTag(tag Tag) error

AddTag 添加 Tag

func AddTags

func AddTags(tags []*Tag) error

AddTags 批量添加 Tags

func CreateUser

func CreateUser(user *User) error

CreateUser 创建 User

func DeleteArticlesByRepo

func DeleteArticlesByRepo(repoName string) error

DeleteArticlesByRepo 删除该 Repo 下的 Article

func DeleteArticlesByTag

func DeleteArticlesByTag(repoName string, tagName string) error

DeleteArticlesByTagID 删除该 Tag 下的 Article

func DeleteRepo

func DeleteRepo(repoName string) error

func DeleteTag

func DeleteTag(repoName string, tagName string) error

DeleteTag 清空某个 repo 下的 tag

func DeleteTagsByRepo

func DeleteTagsByRepo(repoName string) error

DeleteTagsByRepo 清空某个 repo 下的 Tags

func GetAllRepoNames

func GetAllRepoNames() ([]string, error)

func GetArticleList

func GetArticleList(repoName string, tagName string) ([]string, error)

GetArticleList 根据仓库名和标签名获取 Article 列表信息

func GetCurrentRepo

func GetCurrentRepo(userID uint64) (string, error)

GetCurrentRepo 获取用户当前仓库

func GetTagsBySearchName

func GetTagsBySearchName(repoName, tagName string) ([]string, error)

GetTagsBySearchName 根据 repo 名和 tagName 搜索 Tags

func GetTopTagInfosByRepo

func GetTopTagInfosByRepo(repoName string) ([]string, error)

GetTopTagInfosByRepo 根据 repo 名获取所有一级标签的名称

func Init

func Init()

func SetCurrentRepo

func SetCurrentRepo(userID uint64, repo string) error

SetCurrentRepo 设置用户当前仓库

func SetStatus

func SetStatus(userID uint64, status int)

SetStatus 设置用户状态

func TruncateArticles

func TruncateArticles() error

TruncateArticles 清空 Article 表

func TruncateRepo

func TruncateRepo() (err error)

func TruncateTags

func TruncateTags() error

TruncateTags 清空 Tag 表

func UpdateArticle

func UpdateArticle(id uint64, title string, html string) error

UpdateArticle 更新文章

func UpdateUser

func UpdateUser(userID uint64, val map[string]interface{}) error

Update 更新用户

func UpdateUserAllowedRepos

func UpdateUserAllowedRepos(userID uint64, repos []string) error

UpdateUserAllowedRepos 授予用户可访问的仓库列表

Types

type Article

type Article struct {
	ID       uint64 `gorm:"primary_key"`
	Title    string `gorm:"type:varchar(100);index:title;not null"` // 文章标题
	Path     string `gorm:"type:varchar(200);not null"`             // 文件路径
	RawPath  string `gorm:"type:varchar(200);not null"`             // 原始文件路径
	HTML     string `gorm:"type:text"`                              // Markdown 渲染后的 HTML
	TagName  string
	RepoName string
	Tag      Tag  `gorm:"foreignkey:TagName;association_foreignkey:Name;PRELOAD:false;save_associations:false"`  // 标签
	Repo     Repo `gorm:"foreignkey:RepoName;association_foreignkey:Name;PRELOAD:false;save_associations:false"` // 仓库
}

Article 文章

func GetArticle

func GetArticle(repoName string, tagName string, articleName string) (Article, error)

GetArticle 通过仓库名、标签名、文章名获取 Article

func (Article) TableName

func (Article) TableName() string

type ArticleTagInfo

type ArticleTagInfo struct {
	TagName     string `gorm:"column:tag_name" json:"tag"`
	ArticleName string `gorm:"column:title" json:"article"`
}

ArticleTagInfo 标签-文章

func GetArticlesBySearchParam

func GetArticlesBySearchParam(repoName string, articleName string) ([]ArticleTagInfo, error)

GetArticlesBySearchParam 通过仓库名、文章名搜索 Articles

type Articles

type Articles []string

func (Articles) Len

func (a Articles) Len() int

func (Articles) Less

func (a Articles) Less(i, j int) bool

func (Articles) Swap

func (a Articles) Swap(i, j int)

type Repo

type Repo struct {
	ID   uint64 `gorm:"primary_key"`
	Name string `gorm:"type:varchar(50);unique_idx"`
	Path string `gorm:"type:varchar(200);not null"` // 根目录路径
}

func (Repo) TableName

func (Repo) TableName() string

type Tag

type Tag struct {
	ID         uint64         `gorm:"primary_key"`
	Path       string         `gorm:"type:varchar(200);index:path;not null"`             // Tag 目录路径
	Name       string         `gorm:"type:varchar(200);index:name;not null"`             // 标签名称(多级拼合)
	ParentPath sql.NullString `gorm:"type:varchar(200);index:parent_path;default: null"` // 父标签路径
	RepoName   string
	Repo       Repo `gorm:"foreignkey:RepoName;association_foreignkey:Name;PRELOAD:false;save_associations:false"`
}

Tag 标签

func GetRootTagsByRepo

func GetRootTagsByRepo(repoName string) ([]Tag, error)

GetRootTagsByRepo 根据 repo 名获取所有一级标签的 Tag 信息

func GetTag

func GetTag(repoName, tagName string) (Tag, error)

func GetTagsByRepoName

func GetTagsByRepoName(repoName string) ([]Tag, error)

GetTagsByRepo 根据 repo 名获取所有 Tag 信息

func (Tag) TableName

func (Tag) TableName() string

type TagView

type TagView struct {
	Name    string
	SubTags []string // 子标签列表
}

TagView 标签视图

func GetFlatTagView

func GetFlatTagView(repoName string, tagName string) (TagView, error)

GetFlatTagView 通过 TagID 获取平铺的 TagView

func GetTagView

func GetTagView(repoName string, tagName string) (TagView, error)

GetTagView 通过 repoName 和 tagName 获取 TagView

type User

type User struct {
	ID              uint64 `gorm:"primary_key"`
	Email           string `gorm:"type:varchar(100);unique_index"`
	NickName        string `gorm:"size:30"`
	Password        string `json:"-"`
	IsAdmin         bool
	Repos           string   `json:"-"`
	CurrentRepoName string   `json:"current_repo"`
	RepoNames       []string `gorm:"-" json:"repos"`
	ApplyMessage    string   `json:"-"`
	Status          int
}

User 用户

func GetAvailableUserByID

func GetAvailableUserByID(ID interface{}) (User, error)

GetAvailableUserByID 用ID获取可登录用户

func GetUserByEmail

func GetUserByEmail(email string) (User, error)

GetUserByEmail 根据 Email 获取 User

func GetUserByID

func GetUserByID(ID uint64) (User, error)

GetUserByID 根据 ID 获取 User

func (*User) AfterFind

func (user *User) AfterFind() (err error)

AfterFind 钩子:反序列化 Repo 列表

func (*User) CheckPassword

func (user *User) CheckPassword(password string) (bool, error)

CheckPassword 校验密码

func (*User) SetPassword

func (user *User) SetPassword(password string) error

SetPassword 设置密码

func (User) TableName

func (User) TableName() string

type UserApplyInfo

type UserApplyInfo struct {
	ID           uint64
	NickName     string
	ApplyMessage string
}

func GetApplyingUserInfo

func GetApplyingUserInfo() ([]UserApplyInfo, error)

GetApplyingUserInfo 获取申请的用户信息

Jump to

Keyboard shortcuts

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