作者 tangxvhui

更新模型

  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gorm.io/gorm"
  8 +)
  9 +
  10 +type Article struct {
  11 + Id int64
  12 + CreatedAt time.Time
  13 + UpdatedAt time.Time
  14 + DeletedAt gorm.DeletedAt
  15 + AuthorId int64 // 发布人
  16 + Author domain.UserSimple // 发布人
  17 + Title string // 文章标题
  18 + Images []domain.Image // 图片
  19 + WhoRead []int64 // 谁可以看
  20 + WhoReview []int64 // 评论人
  21 + Location domain.Location // 坐标
  22 + CountLove int // 点赞数量
  23 + CountComment int // 评论数量
  24 + Tags []int // 标签
  25 + // ...more
  26 +}
  27 +
  28 +func (m *Article) TableName() string {
  29 + return "article"
  30 +}
  31 +
  32 +func (m *Article) BeforeCreate(tx *gorm.DB) (err error) {
  33 + m.CreatedAt = time.Now()
  34 + m.UpdatedAt = time.Now()
  35 + return
  36 +}
  37 +
  38 +func (m *Article) BeforeUpdate(tx *gorm.DB) (err error) {
  39 + m.UpdatedAt = time.Now()
  40 + return
  41 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gorm.io/gorm"
  8 +)
  9 +
  10 +// 编辑文章后保存的历史记录
  11 +type ArticleBackup struct {
  12 + Id int64
  13 + UpdatedAt time.Time // 更新时间
  14 + DeletedAt gorm.DeletedAt //
  15 + CreatedAt time.Time //
  16 + Operator domain.UserSimple // 操作人
  17 + Title string // 标题
  18 + Section []domain.ArticleSection // 分段内容
  19 + Images []domain.Image // 图片
  20 + Action string // 操作
  21 + WhoRead []int64 // 谁可以看
  22 + WhoReview []int64 // 评论人
  23 + Tags []int // 标签
  24 +}
  25 +
  26 +func (m *ArticleBackup) TableName() string {
  27 + return "article_backup"
  28 +}
  29 +
  30 +func (m *ArticleBackup) BeforeCreate(tx *gorm.DB) (err error) {
  31 + m.CreatedAt = time.Now()
  32 + m.UpdatedAt = time.Now()
  33 + return
  34 +}
  35 +
  36 +func (m *ArticleBackup) BeforeUpdate(tx *gorm.DB) (err error) {
  37 + m.UpdatedAt = time.Now()
  38 + return
  39 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gorm.io/gorm"
  8 +)
  9 +
  10 +// 文章评论
  11 +type ArticleComment struct {
  12 + Id int64 // 评论id
  13 + UpdatedAt time.Time // 更新时间
  14 + DeletedAt gorm.DeletedAt //
  15 + CreatedAt time.Time //
  16 + Pid int64 // 对哪个评论进行回复
  17 + TopId int64 // 归属于最上级的哪个评论
  18 + ArticleId int64 // 文章id
  19 + ArticleSectionId int64 // 文本内容段落id
  20 + SectionContent string // 引用的文章内容文本
  21 + FromUserId int64 // 谁填写的评论
  22 + FromUser domain.UserSimple // 谁填写的评论
  23 + ToUserId int64 // 回复谁的评论
  24 + ToUser domain.UserSimple // 回复谁的评论
  25 + Content string // 评论内容
  26 + CountReply int // 回复数量
  27 + CountUserLove int // 用户点赞数量
  28 + CountAdminLove int // 运营点赞数量
  29 + Show int // 评论的展示状态(0显示、1不显示)
  30 + // ...more
  31 +}
  32 +
  33 +func (m *ArticleComment) TableName() string {
  34 + return "article_comment"
  35 +}
  36 +
  37 +func (m *ArticleComment) BeforeCreate(tx *gorm.DB) (err error) {
  38 + m.CreatedAt = time.Now()
  39 + m.UpdatedAt = time.Now()
  40 + return
  41 +}
  42 +
  43 +func (m *ArticleComment) BeforeUpdate(tx *gorm.DB) (err error) {
  44 + m.UpdatedAt = time.Now()
  45 + return
  46 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  7 + "gorm.io/gorm"
  8 +)
  9 +
  10 +// 填写文章时保存的草稿
  11 +
  12 +type ArticleDraft struct {
  13 + Id int64
  14 + CreatedAt time.Time
  15 + UpdatedAt time.Time
  16 + DeletedAt gorm.DeletedAt
  17 + Template int // 填写内容时用的样板0、无 1、演绎式 2、归纳式
  18 + Content []string // 文章内容
  19 + AuthorId int64 // 发布人
  20 + Title string // 文章标题
  21 + Images []domain.Image // 图片
  22 + WhoRead []int64 // 谁可以看
  23 + WhoReview []int64 // 评论人
  24 + Location domain.Location // 坐标
  25 +}
  26 +
  27 +func (m *ArticleDraft) TableName() string {
  28 + return "article_draft"
  29 +}
  30 +
  31 +func (m *ArticleDraft) BeforeCreate(tx *gorm.DB) (err error) {
  32 + m.CreatedAt = time.Now()
  33 + m.UpdatedAt = time.Now()
  34 + return
  35 +}
  36 +
  37 +func (m *ArticleDraft) BeforeUpdate(tx *gorm.DB) (err error) {
  38 + m.UpdatedAt = time.Now()
  39 + return
  40 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gorm.io/gorm"
  7 +)
  8 +
  9 +// 文章段落
  10 +type ArticleSection struct {
  11 + Id int64
  12 + UpdatedAt time.Time // 更新时间
  13 + DeletedAt gorm.DeletedAt //
  14 + CreatedAt time.Time //
  15 + ArticleId int64 // 文章id
  16 + Content string // 文本内容
  17 + SortBy int // 排序
  18 + TotalComment int // 评论的数量
  19 +}
  20 +
  21 +func (m *ArticleSection) TableName() string {
  22 + return "article_section"
  23 +}
  24 +
  25 +func (m *ArticleSection) BeforeCreate(tx *gorm.DB) (err error) {
  26 + m.CreatedAt = time.Now()
  27 + m.UpdatedAt = time.Now()
  28 + return
  29 +}
  30 +
  31 +func (m *ArticleSection) BeforeUpdate(tx *gorm.DB) (err error) {
  32 + m.UpdatedAt = time.Now()
  33 + return
  34 +}
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
8 ) 8 )
9 9
  10 +// 文章
10 type Article struct { 11 type Article struct {
11 Id int64 `json:"id"` 12 Id int64 `json:"id"`
12 CreatedAt time.Time `json:"createdAt"` 13 CreatedAt time.Time `json:"createdAt"`
@@ -22,9 +23,18 @@ type Article struct { @@ -22,9 +23,18 @@ type Article struct {
22 CountLove int `json:"countLove"` // 点赞数量 23 CountLove int `json:"countLove"` // 点赞数量
23 CountComment int `json:"countComment"` // 评论数量 24 CountComment int `json:"countComment"` // 评论数量
24 Tags []int `json:"tags"` // 标签 25 Tags []int `json:"tags"` // 标签
  26 + Show ArticleShow `json:"showState"` // 评论的展示状态(0显示、1不显示)
25 // ...more 27 // ...more
26 } 28 }
27 29
  30 +// 文章的展示状态(0显示、1不显示)
  31 +type ArticleShow int
  32 +
  33 +const (
  34 + ArticleShowEnable CommentShow = 0
  35 + ArticleShowDisable CommentShow = 1
  36 +)
  37 +
28 type ArticleRepository interface { 38 type ArticleRepository interface {
29 Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 39 Insert(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
30 Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 40 Update(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "context"
  5 + "time"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  8 +)
4 9
5 // 编辑文章后保存的历史记录 10 // 编辑文章后保存的历史记录
6 type ArticleBackup struct { 11 type ArticleBackup struct {
7 - Id int64 12 + Id int64 `json:"id"`
8 UpdatedAt time.Time `json:"updatedAt"` // 更新时间 13 UpdatedAt time.Time `json:"updatedAt"` // 更新时间
9 DeletedAt *time.Time `json:"deletedAt"` // 14 DeletedAt *time.Time `json:"deletedAt"` //
10 CreatedAt time.Time `json:"createdAt"` // 15 CreatedAt time.Time `json:"createdAt"` //
@@ -13,4 +18,15 @@ type ArticleBackup struct { @@ -13,4 +18,15 @@ type ArticleBackup struct {
13 Section []ArticleSection `json:"section"` // 分段内容 18 Section []ArticleSection `json:"section"` // 分段内容
14 Images []Image `json:"images"` // 图片 19 Images []Image `json:"images"` // 图片
15 Action string `json:"action"` // 操作 20 Action string `json:"action"` // 操作
  21 + WhoRead []int64 `json:"whoRead"` // 谁可以看
  22 + WhoReview []int64 `json:"whoReview"` // 评论人
  23 + Tags []int `json:"tags"` // 标签
  24 +}
  25 +
  26 +type ArticleBackupRepository interface {
  27 + Insert(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
  28 + Update(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
  29 + Delete(ctx context.Context, conn transaction.Conn, dm *ArticleBackup) (*ArticleBackup, error)
  30 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleBackup, error)
  31 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleBackup, error)
16 } 32 }
@@ -11,8 +11,8 @@ import ( @@ -11,8 +11,8 @@ import (
11 type ArticleComment struct { 11 type ArticleComment struct {
12 Id int64 `json:"id"` // 评论id 12 Id int64 `json:"id"` // 评论id
13 UpdatedAt time.Time `json:"updatedAt"` // 更新时间 13 UpdatedAt time.Time `json:"updatedAt"` // 更新时间
14 - DeletedAt *time.Time `json:"deletedAt"`  
15 - CreatedAt time.Time `json:"createdAt"` 14 + DeletedAt *time.Time `json:"deletedAt"` //
  15 + CreatedAt time.Time `json:"createdAt"` //
16 Pid int64 `json:"pid"` // 对哪个评论进行回复 16 Pid int64 `json:"pid"` // 对哪个评论进行回复
17 TopId int64 `json:"topId"` // 归属于最上级的哪个评论 17 TopId int64 `json:"topId"` // 归属于最上级的哪个评论
18 ArticleId int64 `json:"articleId"` // 文章id 18 ArticleId int64 `json:"articleId"` // 文章id
@@ -26,7 +26,7 @@ type ArticleComment struct { @@ -26,7 +26,7 @@ type ArticleComment struct {
26 CountReply int `json:"countReply"` // 回复数量 26 CountReply int `json:"countReply"` // 回复数量
27 CountUserLove int `json:"countUserLove"` // 用户点赞数量 27 CountUserLove int `json:"countUserLove"` // 用户点赞数量
28 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 28 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
29 - Show int `json:"showState"` // 评论的展示状态(0显示、1不显示) 29 + Show CommentShow `json:"showState"` // 评论的展示状态(0显示、1不显示)
30 // ...more 30 // ...more
31 } 31 }
32 32
@@ -2,7 +2,6 @@ package domain @@ -2,7 +2,6 @@ package domain
2 2
3 import ( 3 import (
4 "context" 4 "context"
5 - "time"  
6 5
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
8 ) 7 )
@@ -11,10 +10,10 @@ import ( @@ -11,10 +10,10 @@ import (
11 10
12 type ArticleDraft struct { 11 type ArticleDraft struct {
13 Id int64 `json:"id"` 12 Id int64 `json:"id"`
14 - CreatedAt time.Time `json:"createdAt"`  
15 - UpdatedAt time.Time `json:"updatedAt"`  
16 - DeletedAt *time.Time `json:"deletedAt"`  
17 - Template int `json:"template"` // 填写内容时用的样板 1、演绎式 2、归纳式 13 + CreatedAt int64 `json:"createdAt"`
  14 + UpdatedAt int64 `json:"updatedAt"`
  15 + DeletedAt uint `json:"-"`
  16 + Template int `json:"template"` // 填写内容时用的样板0、无 1、演绎式 2、归纳式
18 Content []string `json:"content"` // 文章内容 17 Content []string `json:"content"` // 文章内容
19 AuthorId int64 `json:"authorId"` // 发布人 18 AuthorId int64 `json:"authorId"` // 发布人
20 Title string `json:"title"` // 文章标题 19 Title string `json:"title"` // 文章标题
@@ -11,13 +11,13 @@ import ( @@ -11,13 +11,13 @@ import (
11 11
12 type ArticleTag struct { 12 type ArticleTag struct {
13 Id int64 `json:"id"` 13 Id int64 `json:"id"`
14 - UpdatedAt time.Time `json:"updatedAt"` // 更新时间 14 + UpdatedAt int64 `json:"updatedAt"` // 更新时间
15 DeletedAt *time.Time `json:"deletedAt"` // 15 DeletedAt *time.Time `json:"deletedAt"` //
16 CreatedAt time.Time `json:"createdAt"` // 16 CreatedAt time.Time `json:"createdAt"` //
17 - Image Image `json:"image"` //图片  
18 - Name string `json:"name"` //标签名称  
19 - Group string `json:"group"` //标签分类  
20 - Remark string `json:"remark"` //备注 17 + Image Image `json:"image"` // 图片
  18 + Name string `json:"name"` // 标签名称
  19 + Group string `json:"group"` // 标签分类
  20 + Remark string `json:"remark"` // 备注
21 } 21 }
22 type ArticleTagRepository interface { 22 type ArticleTagRepository interface {
23 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) 23 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
@@ -6,8 +6,8 @@ import "time" @@ -6,8 +6,8 @@ import "time"
6 6
7 type UserLoveFlag struct { 7 type UserLoveFlag struct {
8 Id int64 `json:"id"` 8 Id int64 `json:"id"`
9 - ArticleId int64 `json:"articleId"` //点赞文章时,填文章id  
10 - CommentId int64 `json:"commentId"` //点赞评论时,填评论id 9 + ArticleId int64 `json:"articleId"` // 点赞文章时,文章id
  10 + CommentId int64 `json:"commentId"` // 点赞评论时,填评论id
11 UserId int64 `json:"userId"` 11 UserId int64 `json:"userId"`
12 CreatedAt time.Time `json:"createdAt"` 12 CreatedAt time.Time `json:"createdAt"`
13 UpdatedAt time.Time `json:"updatedAt"` 13 UpdatedAt time.Time `json:"updatedAt"`
1 package domain 1 package domain
2 2
  3 +import "time"
  4 +
3 // 人员查看文章详情后,标记一个记录 5 // 人员查看文章详情后,标记一个记录
  6 +// 浏览记录
4 7
5 type UserReadArticle struct { 8 type UserReadArticle struct {
6 Id int64 `json:"id"` 9 Id int64 `json:"id"`
7 UserId int64 `json:"userId"` 10 UserId int64 `json:"userId"`
8 ArticleId int64 `json:"articleId"` 11 ArticleId int64 `json:"articleId"`
9 Title string `json:"title"` 12 Title string `json:"title"`
10 - ArticleAuthor UserSimple `json:"author"` // 发布人 13 + Author UserSimple `json:"author"` // 发布人
  14 + CreatedAt time.Time `json:"createdAt"`
  15 + UpdatedAt time.Time `json:"updatedAt"`
  16 + DeletedAt *time.Time `json:"deletedAt"`
11 } 17 }