作者 tangxvhui

获取我发布的文章列表

@@ -64,7 +64,10 @@ type ( @@ -64,7 +64,10 @@ type (
64 // 获取我的发文章记录 64 // 获取我的发文章记录
65 type ( 65 type (
66 MiniArticleSearchMeRequest { 66 MiniArticleSearchMeRequest {
67 - AuthorId int64 `json:"-"` 67 + AuthorId int64 `json:"-"`
  68 + CompanyId int64 `json:"-"`
  69 + Page int `json:"page"`
  70 + Size int `json:"size"`
68 } 71 }
69 72
70 MiniArticleSearchMeResponse { 73 MiniArticleSearchMeResponse {
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
10 ) 11 )
11 12
12 func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 13 func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -18,6 +19,9 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,6 +19,9 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
18 } 19 }
19 20
20 l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx) 21 l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
  22 + token := contextdata.GetUserTokenFromCtx(r.Context())
  23 + req.AuthorId = token.UserId
  24 + req.CompanyId = token.CompanyId
21 resp, err := l.MiniArticleSearchMe(&req) 25 resp, err := l.MiniArticleSearchMe(&req)
22 if err != nil { 26 if err != nil {
23 httpx.ErrorCtx(r.Context(), w, err) 27 httpx.ErrorCtx(r.Context(), w, err)
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
10 ) 11 )
11 12
12 func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 13 func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -16,8 +17,10 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -16,8 +17,10 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
16 httpx.ErrorCtx(r.Context(), w, err) 17 httpx.ErrorCtx(r.Context(), w, err)
17 return 18 return
18 } 19 }
  20 + token := contextdata.GetUserTokenFromCtx(r.Context())
19 21
20 l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx) 22 l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
  23 + req.AuthorId = token.UserId
21 resp, err := l.MiniCreateArticle(&req) 24 resp, err := l.MiniCreateArticle(&req)
22 if err != nil { 25 if err != nil {
23 httpx.ErrorCtx(r.Context(), w, err) 26 httpx.ErrorCtx(r.Context(), w, err)
@@ -18,6 +18,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,6 +18,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
18 } 18 }
19 19
20 l := article.NewMiniGetArticleLogic(r.Context(), svcCtx) 20 l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
  21 +
21 resp, err := l.MiniGetArticle(&req) 22 resp, err := l.MiniGetArticle(&req)
22 if err != nil { 23 if err != nil {
23 httpx.ErrorCtx(r.Context(), w, err) 24 httpx.ErrorCtx(r.Context(), w, err)
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 5
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
8 10
9 "github.com/zeromicro/go-zero/core/logx" 11 "github.com/zeromicro/go-zero/core/logx"
10 ) 12 )
@@ -23,8 +25,36 @@ func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext @@ -23,8 +25,36 @@ func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext
23 } 25 }
24 } 26 }
25 27
  28 +// MiniArticleSearchMe 获取我发布的文章
26 func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) { 29 func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
27 - // todo: add your logic here and delete this line 30 + var conn = l.svcCtx.DefaultDBConn()
  31 + queryOptions := domain.NewQueryOptions().
  32 + WithOffsetLimit(req.Page, req.Size).
  33 + MustWithKV("authorId", req.AuthorId)
28 34
  35 + cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
  36 + if err != nil {
  37 + return &types.MiniArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
  38 + }
  39 +
  40 + resp = &types.MiniArticleSearchMeResponse{
  41 + Total: int(cnt),
  42 + List: make([]types.ArticleSearchMe, len(articleList)),
  43 + }
  44 + for i := range articleList {
  45 + images := []string{}
  46 + for _, val2 := range articleList[i].Images {
  47 + images = append(images, val2.Url)
  48 + }
  49 + resp.List[i] = types.ArticleSearchMe{
  50 + Id: articleList[i].Id,
  51 + Title: articleList[i].Title,
  52 + Images: images,
  53 + CreatedAt: articleList[i].CreatedAt,
  54 + CountLove: articleList[i].CountLove,
  55 + CountComment: articleList[i].CountComment,
  56 + Show: int(articleList[i].Show),
  57 + }
  58 + }
29 return 59 return
30 } 60 }
@@ -288,6 +288,9 @@ type MiniArticleGetResponse struct { @@ -288,6 +288,9 @@ type MiniArticleGetResponse struct {
288 288
289 type MiniArticleSearchMeRequest struct { 289 type MiniArticleSearchMeRequest struct {
290 AuthorId int64 `json:"-"` 290 AuthorId int64 `json:"-"`
  291 + CompanyId int64 `json:"-"`
  292 + Page int `json:"page"`
  293 + Size int `json:"size"`
291 } 294 }
292 295
293 type MiniArticleSearchMeResponse struct { 296 type MiniArticleSearchMeResponse struct {
@@ -28,6 +28,7 @@ type Article struct { @@ -28,6 +28,7 @@ type Article struct {
28 CountLove int // 点赞数量 28 CountLove int // 点赞数量
29 CountRead int // 浏览数量 29 CountRead int // 浏览数量
30 CountComment int // 评论数量 30 CountComment int // 评论数量
  31 + Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
31 Show int // 评论的展示状态(0显示、1不显示) 32 Show int // 评论的展示状态(0显示、1不显示)
32 } 33 }
33 34
@@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti @@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti
111 return repository.ModelToDomainModel(m) 111 return repository.ModelToDomainModel(m)
112 } 112 }
113 113
114 -func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Article, error) { 114 +func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
115 var ( 115 var (
116 tx = conn.DB() 116 tx = conn.DB()
117 ms []*models.Article 117 ms []*models.Article
@@ -119,7 +119,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -119,7 +119,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
119 total int64 119 total int64
120 ) 120 )
121 queryFunc := func() (interface{}, error) { 121 queryFunc := func() (interface{}, error) {
122 - tx = tx.Model(&ms).Order("id desc") 122 + tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId)
  123 +
  124 + if v, ok := queryOptions["authorId"]; ok {
  125 + tx = tx.Where("author_id = ?", v)
  126 + }
  127 +
123 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 128 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
124 return dms, tx.Error 129 return dms, tx.Error
125 } 130 }
@@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti @@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
125 Order("id desc") 125 Order("id desc")
126 126
127 if v, ok := queryOptions["name"]; ok { 127 if v, ok := queryOptions["name"]; ok {
128 - tx.Where("id like ?", v) 128 + tx = tx.Where("name like ?", v)
129 } 129 }
130 if v, ok := queryOptions["group"]; ok { 130 if v, ok := queryOptions["group"]; ok {
131 - tx.Where("group like ?", v) 131 + tx = tx.Where("group like ?", v)
132 } 132 }
133 133
134 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 134 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
@@ -26,7 +26,7 @@ type Article struct { @@ -26,7 +26,7 @@ type Article struct {
26 CountComment int `json:"countComment"` // 评论数量 26 CountComment int `json:"countComment"` // 评论数量
27 CountRead int `json:"countRead"` // 浏览数量 27 CountRead int `json:"countRead"` // 浏览数量
28 Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示) 28 Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示)
29 - Tags []int64 `json:"tags"` 29 + Tags []int64 `json:"tags"` // 定性标签
30 // ...more 30 // ...more
31 } 31 }
32 32
@@ -36,7 +36,7 @@ type ArticleRepository interface { @@ -36,7 +36,7 @@ type ArticleRepository interface {
36 Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 36 Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
37 UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 37 UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
38 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) 38 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
39 - Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error) 39 + Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
40 } 40 }
41 41
42 type ArticleTarget int 42 type ArticleTarget int
@@ -74,6 +74,7 @@ func (a ArticleShow) Named() string { @@ -74,6 +74,7 @@ func (a ArticleShow) Named() string {
74 return "" 74 return ""
75 } 75 }
76 76
  77 +// 设置文章的备份数据
77 func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup { 78 func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
78 b := ArticleBackup{ 79 b := ArticleBackup{
79 Id: 0, 80 Id: 0,