articles

package
v0.2.55 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 8 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

func DecrementLike(entity Entity) int64

func DecrementReplyFast

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

func Delete

func Delete(entity *Entity) int64

func GetMapByIds

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

func GetMaxId

func GetMaxId() uint64

func IncrementLike

func IncrementLike(entity Entity) int64

func IncrementReplyFast

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

func IncrementViews

func IncrementViews(counts map[uint64]uint64) error

func Page

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

func PageForModeration

func PageForModeration(q ModerationPageQuery) struct {
	Page     int
	PageSize int
	Total    int64
	HasNext  bool
	Data     []SmallEntity
}

func ReserveReplySequence

func ReserveReplySequence(articleId uint64) (uint64, error)

func Save

func Save(entity *Entity) error

func SaveNoUpdate

func SaveNoUpdate(entity *Entity) error

func UpdatePinWeight

func UpdatePinWeight(id uint64, pinWeight int) error

func UpdateProcessStatus

func UpdateProcessStatus(id uint64, processStatus int8) error

Types

type Entity

type Entity struct {
	Id uint64 `` //
	/* 314-byte string literal not displayed */
	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
	FirstImageURL   string   `gorm:"column:first_image_url;type:varchar(512);not null;default:'';" json:"firstImageUrl"`           // 正文首图,用于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   ``                                                                                                    //
	/* 137-byte string literal not displayed */
	Posters       []Poster `gorm:"column:posters;type:text;serializer:json" json:"posters"`
	ArticleStatus int8     `` // 文章状态:0 草稿 1 发布
	/* 307-byte string literal not displayed */
	ProcessStatus int8 `` // 管理状态:0 正常 1 封禁
	/* 307-byte string literal not displayed */
	LikeCount uint64 `gorm:"column:like_count;type:bigint unsigned;not null;default:0;" json:"likeCount"` // 喜欢数量
	ViewCount uint64 ``                                                                                   // 访问数量
	/* 135-byte string literal not displayed */
	ReplyCount uint64 `` // 评论数量
	/* 133-byte string literal not displayed */
	ReplySeq  uint64         `gorm:"column:reply_seq;type:bigint unsigned;not null;default:0;" json:"replySeq"`                                            // 历史最大回复序号
	PinWeight int            `gorm:"column:pin_weight;type:int;not null;default:0;index:idx_articles_list_default,priority:3,sort:desc;" json:"pinWeight"` // 全站置顶权重,0 表示不置顶
	CreatedAt time.Time      `gorm:"column:created_at;autoCreateTime;<-:create;index:idx_articles_list_new,priority:3,sort:desc;" json:"createdAt"`        //
	UpdatedAt time.Time      `gorm:"column:updated_at;autoUpdateTime;index:idx_articles_list_default,priority:4,sort:desc;" json:"updatedAt"`
	DeletedAt gorm.DeletedAt //
}

func Get

func Get(id any) (entity Entity)

func GetLast

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

func GetLatestArticlesWithContent

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

func QueryById

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

QueryById 根据ID批量查询文章

func (*Entity) TableName

func (itself *Entity) TableName() string

type ModerationPageQuery

type ModerationPageQuery struct {
	Page, PageSize      int
	FilterProcessStatus bool
	ProcessStatus       int8
	CategoryIDs         []uint64
}

type PageQuery

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

type Poster

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
	FirstImageURL string         `gorm:"column:first_image_url;type:varchar(512);not null;default:'';" json:"firstImageUrl"`           // 正文首图,用于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"` // 评论
	ReplySeq      uint64         `gorm:"column:reply_seq;type:bigint unsigned;not null;default:0;" json:"replySeq"`     // 历史最大回复序号
	LikeCount     uint64         `gorm:"column:like_count;type:bigint unsigned;not null;default:0;" json:"likeCount"`   // 被喜欢
	PinWeight     int            `gorm:"column:pin_weight;type:int;not null;default:0;" json:"pinWeight"`               // 全站置顶权重,0 表示不置顶
	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 GetByIds

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

func GetDraftArticlesByUserId

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

func GetLatestArticles

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

GetLatestArticles 获取最新的n篇文章

func GetLatestArticlesByUserId

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

func GetPublishedArticlesByUserBeforeId

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

func GetSimple

func GetSimple(id any) (entity SmallEntity)

func (*SmallEntity) GetPosters

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

func (*SmallEntity) PubDate

func (itself *SmallEntity) PubDate() string

func (*SmallEntity) TableName

func (itself *SmallEntity) TableName() string

type Type

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