articles

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 5 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 Delete

func Delete(entity *Entity) int64

func GetCount

func GetCount() int64

func GetMapByIds

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

func GetMaxId

func GetMaxId() uint64

func IncrementReply

func IncrementReply(entity Entity) int64

func IncrementView

func IncrementView(entity Entity) int64

func Page

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

func Save

func Save(entity *Entity) error

func SaveAll

func SaveAll(entities *[]Entity) int64

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"`                                          //
	Type          int8       `gorm:"column:type;type:tinyint;not null;default:0;" json:"type"`                          // 文章类型:0 博文,1教程,2问答,3分享
	UserId        uint64     `gorm:"column:user_id;type:bigint unsigned;not null;default:0;" json:"userId"`             //
	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;index;type:bigint unsigned;not null;default:0;" json:"viewCount"` // 访问数量
	ReplyCount    uint64     `gorm:"column:reply_count;type:bigint unsigned;not null;default:0;" json:"replyCount"`     // 访问数量
	CreatedAt     time.Time  `gorm:"column:created_at;autoCreateTime;" json:"createdAt"`                                //
	UpdatedAt     time.Time  `gorm:"column:updated_at;autoUpdateTime;index;" json:"updatedAt"`
	DeletedAt     *time.Time `gorm:"column:deleted_at;type:datetime;" json:"deletedAt"` //
}

func All

func All() (entities []*Entity)

func Get

func Get(id any) (entity Entity)

func GetByIds

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

func GetByUserAndTitle

func GetByUserAndTitle(userId, title any) (entity Entity)

func (*Entity) TableName

func (itself *Entity) TableName() string

type PageQuery

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

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"`              //
	Type          int8       `gorm:"column:type;type:tinyint;not null;default:0;" json:"type"`                      // 文章类型:0 博文,1教程,2问答,3分享
	UserId        uint64     `gorm:"column:user_id;type:bigint unsigned;not null;default:0;" json:"userId"`         //
	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"` // 访问数量
	CreatedAt     time.Time  `gorm:"column:created_at;autoCreateTime;" json:"createdAt"`                            //
	UpdatedAt     time.Time  `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`
	DeletedAt     *time.Time `gorm:"column:deleted_at;type:datetime;" json:"deletedAt"` //
}

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 (*SmallEntity) TableName

func (itself *SmallEntity) TableName() string

Jump to

Keyboard shortcuts

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