article.go 3.4 KB
package domain

import (
	"context"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)

// 文章
type Article struct {
	Id           int64         `json:"id"`
	CompanyId    int64         `json:"companyId"`
	CreatedAt    int64         `json:"createdAt,omitempty"`
	UpdatedAt    int64         `json:"updatedAt,omitempty"`
	DeletedAt    int64         `json:"deletedAt,omitempty"`
	Version      int           `json:"version,omitempty"`
	AuthorId     int64         `json:"authorId"`     // 发布人
	Author       UserSimple    `json:"author"`       // 发布人
	Title        string        `json:"title"`        // 文章标题
	Images       []Image       `json:"images"`       // 图片
	WhoRead      []int64       `json:"whoRead"`      // 谁可以看
	WhoReview    []int64       `json:"whoReview"`    // 评论人
	Location     Location      `json:"location"`     // 坐标
	TargetUser   ArticleTarget `json:"targetUser"`   // 分发方式 0 分发给所有人 1 分发给指定的人
	CountLove    int           `json:"countLove"`    // 点赞数量
	CountComment int           `json:"countComment"` // 评论数量
	CountRead    int           `json:"countRead"`    // 浏览数量
	Show         ArticleShow   `json:"show"`         // 评论的展示状态(0显示、1不显示)
	Tags         []int64       `json:"tags"`         // 定性标签
	// ...more
}

type ArticleRepository interface {
	Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
	Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
	Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
	IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error    //点赞数量变动
	IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动
	IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error    //浏览数量变动
}

type ArticleTarget int

const (
	ArticleTargetAll   ArticleTarget = 0 //内容分发给所有人
	ArticleTargetLimit ArticleTarget = 1 //分发给指定的人
)

func (a ArticleTarget) Named() string {
	switch a {
	case ArticleTargetAll:
		return "所以人"
	case ArticleTargetLimit:
		return "指定人"
	}
	return ""
}

// 文章的展示状态(0显示、1不显示)
type ArticleShow int

const (
	ArticleShowEnable  ArticleShow = 0
	ArticleShowDisable ArticleShow = 1
)

func (a ArticleShow) Named() string {
	switch a {
	case ArticleShowEnable:
		return "显示"
	case ArticleShowDisable:
		return "隐藏"
	}
	return ""
}

// 设置文章的备份数据
func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
	b := ArticleBackup{
		Id:         0,
		CompanyId:  0,
		CreatedAt:  0,
		UpdatedAt:  0,
		DeletedAt:  0,
		Version:    0,
		Operator:   operator,
		Title:      m.Title,
		Section:    section,
		Images:     m.Images,
		Action:     "",
		TargetUser: m.TargetUser,
		WhoRead:    m.WhoRead,
		WhoReview:  m.WhoReview,
		Tags:       m.Tags,
	}
	return &b
}