articles

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CantWriteNew

func CantWriteNew(userId uint64, maxCount int64) bool

func Create

func Create(entity *Entity) int64

func DecrementLike added in v0.0.2

func DecrementLike(entity Entity) int64

func DecrementReplyFast added in v0.1.1

func DecrementReplyFast(articleId uint64, posters []Poster) error

func Delete

func Delete(entity *Entity) int64

func GetCountGroupByDay added in v0.1.1

func GetCountGroupByDay() ([]map[string]any, error)

GetCountGroupByDay groups article counts by day.

func GetMapByIds

func GetMapByIds(ids []uint64) map[uint64]*SmallEntity

func GetMaxId

func GetMaxId() uint64

func GetUserCount added in v0.0.3

func GetUserCount(userId uint64) int64

func IncrementLike added in v0.0.2

func IncrementLike(entity Entity) int64

func IncrementReply

func IncrementReply(entity Entity) int64

func IncrementReplyFast added in v0.1.1

func IncrementReplyFast(articleId uint64, posters []Poster) error

func IncrementView

func IncrementView(entity Entity) int64

func Page

func Page[ResType SmallEntity](q PageQuery) struct {
	Page     int
	PageSize int
	Total    int64
	Data     []ResType
}

func Save

func Save(entity *Entity) error

func SaveNoUpdate added in v0.0.2

func SaveNoUpdate(entity *Entity) error

func UpdatePosters added in v0.1.1

func UpdatePosters(id uint64, posters []Poster) error

Types

type Entity

type Entity struct {
	Id              uint64   `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`                                       //
	Title           string   `gorm:"column:title;type:varchar(512);not null;default:'';" json:"title"`                             //
	Content         string   `gorm:"column:content;type:text;" json:"content"`                                                     //
	Description     string   `gorm:"column:description;type:varchar(255);not null;default:'';" json:"description"`                 // 文章描述,用于SEO
	RenderedHTML    string   `gorm:"column:rendered_html;type:text;" json:"renderedHTML"`                                          //md 渲染后数据
	RenderedVersion uint32   `gorm:"column:rendered_version;type:bigint unsigned;not null;default:0;" json:"renderedVersion"`      //md 的渲染器版本
	Type            int8     `gorm:"column:type;type:tinyint;not null;default:0;" json:"type"`                                     // 文章类型:0 博文,1教程,2问答,3分享
	CategoryId      []uint64 `gorm:"column:category_id;type:varchar(255);not null;default:'[]';serializer:json" json:"categoryId"` // 分类
	UserId          uint64   `gorm:"column:user_id;type:bigint unsigned;not null;default:0;index:idx_user_status;" json:"userId"`  //
	Posters         []Poster `gorm:"column:posters;type:text;serializer:json" json:"posters"`
	ArticleStatus   int8     `` // 文章状态:0 草稿 1 发布
	/* 131-byte string literal not displayed */
	ProcessStatus int8 `` // 管理状态:0 正常 1 封禁
	/* 132-byte string literal not displayed */
	LikeCount  uint64         `gorm:"column:like_count;type:bigint unsigned;not null;default:0;" json:"likeCount"`         // 喜欢数量
	ViewCount  uint64         `gorm:"column:view_count;index;type:bigint unsigned;not null;default:0;" json:"viewCount"`   // 访问数量
	ReplyCount uint64         `gorm:"column:reply_count;type:bigint unsigned;not null;default:0;index;" json:"replyCount"` // 评论数量
	CreatedAt  time.Time      `gorm:"column:created_at;autoCreateTime;<-:create;" json:"createdAt"`                        //
	UpdatedAt  time.Time      `gorm:"column:updated_at;autoUpdateTime;index:idx_updated_at_status,priority:1;" json:"updatedAt"`
	DeletedAt  gorm.DeletedAt //
}

func Get

func Get(id any) (entity Entity)

func GetBatch added in v0.1.1

func GetBatch(minId uint64, limit int) (entities []*Entity)

func GetLast added in v0.1.1

func GetLast(limit int) (entities []*Entity)

func GetLatestArticlesWithContent added in v0.1.1

func GetLatestArticlesWithContent(limit int) ([]Entity, error)

func QueryById added in v0.0.3

func QueryById(startId uint64, limit int) (entities []*Entity)

QueryById 根据ID批量查询文章

func (*Entity) TableName

func (itself *Entity) TableName() string

type PageQuery

type PageQuery struct {
	Page, PageSize int
	Search         string
	UserId         uint64
	FilterStatus   bool
	Categories     []int
	Sort           string
}

type Poster added in v0.1.1

type Poster struct {
	UserID      uint64 `json:"user_id"`
	Description string `json:"description"`
}

Poster stores one participant avatar entry.

type SmallEntity

type SmallEntity struct {
	Id            uint64         `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`                                       //
	Title         string         `gorm:"column:title;type:varchar(512);not null;default:'';" json:"title"`                             //
	Description   string         `gorm:"column:description;type:varchar(255);not null;default:'';" json:"description"`                 // 文章描述,用于SEO
	Type          int8           `gorm:"column:type;type:tinyint;not null;default:0;" json:"type"`                                     // 文章类型:0 博文,1教程,2问答,3分享
	CategoryId    []uint64       `gorm:"column:category_id;type:varchar(255);not null;default:'[]';serializer:json" json:"categoryId"` // 分类
	UserId        uint64         `gorm:"column:user_id;type:bigint unsigned;not null;default:0;" json:"userId"`                        //
	Posters       []Poster       `gorm:"column:posters;type:text;serializer:json" json:"posters"`
	ArticleStatus int8           `gorm:"column:article_status;type:tinyint;not null;default:0;" json:"articleStatus"`   // 文章状态:0 草稿 1 发布
	ProcessStatus int8           `gorm:"column:process_status;type:tinyint;not null;default:0;" json:"processStatus"`   // 管理状态:0 正常 1 封禁
	ViewCount     uint64         `gorm:"column:view_count;type:bigint unsigned;not null;default:0;" json:"viewCount"`   // 访问数量
	ReplyCount    uint64         `gorm:"column:reply_count;type:bigint unsigned;not null;default:0;" json:"replyCount"` // 评论
	LikeCount     uint64         `gorm:"column:like_count;type:bigint unsigned;not null;default:0;" json:"likeCount"`   // 被喜欢
	CreatedAt     time.Time      `gorm:"column:created_at;autoCreateTime;<-:create;" json:"createdAt"`                  //
	UpdatedAt     time.Time      `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`
	DeletedAt     gorm.DeletedAt //
}

func GetAllSimple added in v0.1.1

func GetAllSimple(offset, limit int) ([]*SmallEntity, error)

GetAllSimple returns paginated simple entities for export and repair jobs.

func GetByIds

func GetByIds(ids []uint64) (entities []*SmallEntity)

func GetLatestArticles

func GetLatestArticles(limit int) ([]SmallEntity, error)

GetLatestArticles 获取最新的n篇文章

func GetLatestArticlesByUserId

func GetLatestArticlesByUserId(userId uint64, limit int) ([]*SmallEntity, error)

func GetRecommendedArticles

func GetRecommendedArticles(limit int) ([]SmallEntity, error)

func GetRecommendedArticlesByAuthorId

func GetRecommendedArticlesByAuthorId(authorId uint64, limit int) ([]*SmallEntity, error)

func GetSimple added in v0.1.1

func GetSimple(id any) (entity SmallEntity)

func (*SmallEntity) GetPosters added in v0.1.1

func (itself *SmallEntity) GetPosters() []Poster

func (*SmallEntity) PubDate added in v0.0.6

func (itself *SmallEntity) PubDate() string

func (*SmallEntity) TableName

func (itself *SmallEntity) TableName() string

type Type added in v0.1.1

type Type int
const (
	Share Type = iota + 1
	Help
)

Jump to

Keyboard shortcuts

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