article_section.go 1.7 KB
package domain

import (
	"context"

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

// 文章段落内容
type ArticleSection 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"`
	ArticleId    int64  `json:"articleId"`    // 文章id
	Content      string `json:"content"`      // 文本内容
	SortBy       int    `json:"sortBy"`       // 排序
	TotalComment int    `json:"totalComment"` // 评论的数量
}

type ArticleSectionRepository interface {
	Insert(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
	Update(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error)
	Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error)
	IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error //评论数量变动
}

// 排序文章分段列表
type SortArticleSection []*ArticleSection

func (a SortArticleSection) Len() int           { return len(a) }
func (a SortArticleSection) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortArticleSection) Less(i, j int) bool { return a[i].SortBy < a[j].SortBy }