model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionAll    = "all"
	PermissionCreate = "create"
	PermissionUpdate = "update"
	PermissionRead   = "read"
	PermissionDelete = "delete"
)
View Source
const (
	GroupRoleAdmin  = "admin"
	GroupRoleMember = "member"
)
View Source
const (
	GroupTypeAdmin = "admin" // carrot admin, for /admin path with permissions check
	GroupTypeApp   = "app"
)
View Source
const TableNameCategory = "categories"
View Source
const TableNameComment = "comments"
View Source
const TableNameConfig = "configs"
View Source
const TableNameMedia = "medias"
View Source
const TableNamePage = "pages"
View Source
const TableNamePost = "posts"
View Source
const TableNameUser = "users"

Variables

This section is empty.

Functions

func CreateFolder

func CreateFolder(db *gorm.DB, parent, name string, user *User) (string, error)

func GenUniqueKey

func GenUniqueKey(tx *gorm.DB, field string, size int) (key string)

GenUniqueKey generate a unique value for a field in a table.

func GetTagsByCategory

func GetTagsByCategory(db *gorm.DB, contentType string, form *TagsForm) ([]string, error)

Query tags by category

func MakeDuplicate

func MakeDuplicate(db *gorm.DB, obj any) error

func MakePublish

func MakePublish(db *gorm.DB, siteID, ID string, obj any, publish bool) error

func QueryContentByTags

func QueryContentByTags(db *gorm.DB, contentType string, form *QueryByTagsForm) ([]string, error)

func QueryTags

func QueryTags(db *gorm.DB) ([]string, error)

func SafeDraft

func SafeDraft(db *gorm.DB, siteID, ID string, obj any, draft string) error

Types

type BaseContent

type BaseContent struct {
	UpdatedAt   time.Time    `json:"updatedAt" gorm:"index"`
	CreatedAt   time.Time    `json:"createdAt" gorm:"index"`
	Thumbnail   string       `json:"thumbnail,omitempty" gorm:"size:500"`
	Tags        string       `json:"tags,omitempty" gorm:"size:200;index"`
	Title       string       `json:"title,omitempty" gorm:"size:200"`
	Alt         string       `json:"alt,omitempty"`
	Description string       `json:"description,omitempty"`
	Keywords    string       `json:"keywords,omitempty"`
	CreatorID   uint         `json:"-"`
	Creator     User         `json:"-"`
	Author      string       `json:"author" gorm:"size:64"`
	Published   bool         `json:"published"`
	PublishedAt sql.NullTime `json:"publishedAt"`
	ContentType string       `json:"contentType" gorm:"size:32"`
	Remark      string       `json:"remark"`
}

type Category

type Category struct {
	SiteID string        `json:"siteId" gorm:"uniqueIndex:,composite:_site_uuid"`
	Site   Site          `json:"-"`
	UUID   string        `json:"uuid" gorm:"size:12;uniqueIndex:,composite:_site_uuid"`
	Name   string        `json:"name" gorm:"size:200"`
	Items  CategoryItems `json:"items,omitempty"`
	Count  int           `json:"count" gorm:"-"`
}

func QueryCategoryWithCount

func QueryCategoryWithCount(db *gorm.DB, siteId, contentObject string) ([]Category, error)

func (*Category) FindItem

func (category *Category) FindItem(path string) *CategoryItem

func (*Category) TableName

func (*Category) TableName() string

type CategoryItem

type CategoryItem struct {
	Path     string              `json:"path"`
	Name     string              `json:"name"`
	Icon     *object.ContentIcon `json:"icon,omitempty"`
	Children CategoryItems       `json:"children,omitempty"`
	Count    int                 `json:"count" gorm:"-"`
}

func (*CategoryItem) Scan

func (s *CategoryItem) Scan(input interface{}) error

func (CategoryItem) Value

func (s CategoryItem) Value() (driver.Value, error)

type CategoryItems

type CategoryItems []CategoryItem

func (*CategoryItems) Scan

func (s *CategoryItems) Scan(input interface{}) error

func (CategoryItems) Value

func (s CategoryItems) Value() (driver.Value, error)

type Comment

type Comment struct {
	gorm.Model
	Body   string `gorm:"column:body;not null" json:"body"`
	Email  string `gorm:"column:email;not null" json:"email"`
	IP     string `gorm:"column:ip;not null" json:"ip"`
	Post   Post
	PostID uint
	UserID uint `gorm:"column:user_id;not null" json:"user_id"`
	User   User
}

func (*Comment) TableName

func (*Comment) TableName() string

type Config

type Config struct {
	ID    uint   `json:"id" gorm:"primaryKey"`
	Key   string `json:"key" gorm:"size:128;uniqueIndex"`
	Desc  string `json:"desc" gorm:"size:200"`
	Value string
}

func (*Config) TableName

func (*Config) TableName() string

type ContentQueryResult

type ContentQueryResult struct {
	*object.QueryResult
	Relations   []RelationContent `json:"relations,omitempty"`
	Suggestions []RelationContent `json:"suggestions,omitempty"`
}

type Group

type Group struct {
	ID         uint            `json:"-" gorm:"primaryKey"`
	CreatedAt  time.Time       `json:"-" gorm:"autoCreateTime"`
	UpdatedAt  time.Time       `json:"-"`
	Name       string          `json:"name" gorm:"size:200"`
	Type       string          `json:"type" gorm:"size:24;index"`
	Extra      string          `json:"extra"`
	Permission GroupPermission `json:"-"`
}

func (Group) String

func (g Group) String() string

type GroupMember

type GroupMember struct {
	ID        uint      `json:"-" gorm:"primaryKey"`
	CreatedAt time.Time `json:"-" gorm:"autoCreateTime"`
	UserID    uint      `json:"-"`
	User      User      `json:"user"`
	GroupID   uint      `json:"-"`
	Group     Group     `json:"group"`
	Role      string    `json:"role" gorm:"size:60"`
}

type GroupPermission

type GroupPermission struct {
	Permissions []string
}

permission format users.read,users.create,users.update,users.delete, user.* pages.publish,pages.update,page.delete,page.*

func (*GroupPermission) Scan

func (p *GroupPermission) Scan(value interface{}) error

func (GroupPermission) Value

func (p GroupPermission) Value() (driver.Value, error)

type Media

type Media struct {
	BaseContent
	Size       int64  `json:"size"`
	Directory  bool   `json:"directory" gorm:"index"`
	Path       string `json:"path" gorm:"size:200;uniqueIndex:,composite:_path_name"`
	Name       string `json:"name" gorm:"size:200;uniqueIndex:,composite:_path_name"`
	Ext        string `json:"ext" gorm:"size:100"`
	Dimensions string `json:"dimensions" gorm:"size:200"` // x*y
	StorePath  string `json:"-" gorm:"size:300"`
	External   bool   `json:"external"`
	PublicUrl  string `json:"publicUrl,omitempty" gorm:"-"`
}

func (*Media) BuildPublicUrls

func (m *Media) BuildPublicUrls(mediaHost string, mediaPrefix string)

func (*Media) TableName

func (*Media) TableName() string

type MediaFolder

type MediaFolder struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	FilesCount   int64  `json:"filesCount"`
	FoldersCount int64  `json:"foldersCount"`
}

func ListFolders

func ListFolders(db *gorm.DB, path string) ([]MediaFolder, error)

type Page

type Page struct {
	BaseContent
	SiteID       string `json:"siteId" gorm:"primaryKey;uniqueIndex:,composite:_site_id"`
	Site         Site   `json:"-"`
	ID           string `json:"id" gorm:"primaryKey;size:100;uniqueIndex:,composite:_site_id"`
	IsDraft      bool   `json:"isDraft"`
	Draft        string `json:"-"`
	Body         string `json:"body"`
	PreviewURL   string `json:"previewUrl,omitempty" gorm:"size:200"`
	CategoryID   string `json:"categoryId,omitempty" gorm:"size:64;index:,composite:_category_id_path" label:"Category"`
	CategoryPath string `json:"categoryPath,omitempty" gorm:"size:64;index:,composite:_category_id_path"`
}

func (*Page) TableName

func (*Page) TableName() string

type Post

type Post struct {
	BaseContent
	SiteID       string `json:"siteId" gorm:"primaryKey;uniqueIndex:,composite:_site_id"`
	Site         Site   `json:"-"`
	ID           string `json:"id" gorm:"primaryKey;size:100;uniqueIndex:,composite:_site_id"`
	IsDraft      bool   `json:"isDraft"`
	Draft        string `json:"-"`
	Body         string `json:"body"`
	PreviewURL   string `json:"previewUrl,omitempty" gorm:"size:200"`
	CategoryID   string `json:"categoryId,omitempty" gorm:"size:64;index:,composite:_category_id_path" label:"Category"`
	CategoryPath string `json:"categoryPath,omitempty" gorm:"size:64;index:,composite:_category_id_path"`
}

func (*Post) TableName

func (*Post) TableName() string

type Profile

type Profile struct {
	Avatar  string         `json:"avatar,omitempty"`
	Gender  string         `json:"gender,omitempty"`
	City    string         `json:"city,omitempty"`
	Region  string         `json:"region,omitempty"`
	Country string         `json:"country,omitempty"`
	Extra   map[string]any `json:"extra,omitempty"`
}

func (*Profile) Scan

func (p *Profile) Scan(value interface{}) error

func (Profile) Value

func (p Profile) Value() (driver.Value, error)

type PublishLog

type PublishLog struct {
	ID        uint      `json:"id" gorm:"primarykey"`
	CreatedAt time.Time `json:"createdAt"`
	AuthorID  uint      `json:"-"`
	Author    User      `json:"author"`
	Content   string    `json:"content" gorm:"size:12;index:idx_content_with_id"`    // post_id or page_id
	ContentID string    `json:"contentId" gorm:"size:100;index:idx_content_with_id"` // post_id or page_id
	Body      string    `json:"body"`
}

type QueryByTagsForm

type QueryByTagsForm struct {
	Tags  []string `json:"tags" binding:"required"`
	Limit int      `json:"limit"`
	Pos   int      `json:"pos"`
	TagsForm
}

type QueryByTagsResult

type QueryByTagsResult struct {
	Items []any `json:"items"`
	Total int   `json:"total"`
	Limit int   `json:"limit"`
	Pos   int   `json:"pos"`
}

type RelationContent

type RelationContent struct {
	BaseContent
	SiteID string `json:"siteId"`
	ID     string `json:"id"`
}

func GetRelations

func GetRelations(db *gorm.DB, siteId, categoryId, categoryPath, postId string, maxCount int) ([]RelationContent, error)

func GetSuggestions

func GetSuggestions(db *gorm.DB, siteId, categoryId, categoryPath, postId string, maxCount int) ([]RelationContent, error)

type RenderCategory

type RenderCategory struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	Path     string `json:"path,omitempty"`
	PathName string `json:"pathName,omitempty"`
}

func NewRenderCategory

func NewRenderCategory(db *gorm.DB, categoryID, categoryPath string) *RenderCategory

type RenderContent

type RenderContent struct {
	BaseContent
	ID          string            `json:"id"`
	SiteID      string            `json:"siteId"`
	Category    *RenderCategory   `json:"category,omitempty"`
	PageData    any               `json:"data,omitempty"`
	PostBody    string            `json:"body,omitempty"`
	IsDraft     bool              `json:"isDraft"`
	Relations   []RelationContent `json:"relations,omitempty"`
	Suggestions []RelationContent `json:"suggestions,omitempty"`
}

func NewRenderContentFromPage

func NewRenderContentFromPage(db *gorm.DB, page *Page) *RenderContent

func NewRenderContentFromPost

func NewRenderContentFromPost(db *gorm.DB, post *Post, relations bool) *RenderContent

type Site

type Site struct {
	UpdatedAt time.Time `json:"updatedAt"`
	CreatedAt time.Time `json:"createdAt"`
	Domain    string    `json:"domain" gorm:"primarykey;size:200"`
	Name      string    `json:"name" gorm:"size:200"`
	Preview   string    `json:"preview" gorm:"size:200"`
	Disallow  bool      `json:"disallow"`
}

func (Site) String

func (s Site) String() string

type StringArray

type StringArray []string

func (*StringArray) Scan

func (s *StringArray) Scan(input interface{}) error

func (StringArray) Value

func (s StringArray) Value() (driver.Value, error)

type SummaryResult

type SummaryResult struct {
	SiteCount     int64            `json:"sites"`
	PageCount     int64            `json:"pages"`
	PostCount     int64            `json:"posts"`
	CategoryCount int64            `json:"categories"`
	MediaCount    int64            `json:"media"`
	LatestPosts   []*RenderContent `json:"latestPosts"`
	BuildTime     string           `json:"buildTime"`
	CanExport     bool             `json:"canExport"`
}

func GetSummary

func GetSummary(db *gorm.DB) (result SummaryResult)

type TagsForm

type TagsForm struct {
	SiteId       string `json:"siteId"`
	CategoryId   string `json:"categoryId"`
	CategoryPath string `json:"categoryPath"`
}

type User

type User struct {
	ID        uint      `json:"-" gorm:"primaryKey"`
	CreatedAt time.Time `json:"-" gorm:"autoCreateTime"`
	UpdatedAt time.Time `json:"-" gorm:"autoUpdateTime"`

	Email       string     `json:"email" gorm:"size:128;uniqueIndex"`
	Password    string     `json:"-" gorm:"size:128"`
	Phone       string     `json:"phone,omitempty" gorm:"size:64;index"`
	FirstName   string     `json:"firstName,omitempty" gorm:"size:128"`
	LastName    string     `json:"lastName,omitempty" gorm:"size:128"`
	DisplayName string     `json:"displayName,omitempty" gorm:"size:128"`
	IsSuperUser bool       `json:"-"`
	IsStaff     bool       `json:"-"`
	Enabled     bool       `json:"-"`
	Activated   bool       `json:"-"`
	LastLogin   *time.Time `json:"lastLogin,omitempty"`
	LastLoginIP string     `json:"-" gorm:"size:128"`

	Source    string   `json:"-" gorm:"size:64;index"`
	Locale    string   `json:"locale,omitempty" gorm:"size:20"`
	Timezone  string   `json:"timezone,omitempty" gorm:"size:200"`
	Profile   *Profile `json:"profile,omitempty"`
	AuthToken string   `json:"token,omitempty" gorm:"-"`
}

func (*User) GetProfile

func (u *User) GetProfile() Profile

func (*User) GetVisibleName

func (u *User) GetVisibleName() string

func (User) String

func (u User) String() string

func (*User) TableName

func (*User) TableName() string

Jump to

Keyboard shortcuts

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