作者 tangxvhui

调整创建内容的接口

@@ -30,13 +30,13 @@ service Core { @@ -30,13 +30,13 @@ service Core {
30 @handler MiniSetUserLike 30 @handler MiniSetUserLike
31 post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse) 31 post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
32 32
33 - @doc "小程序获取文章的编辑记录"  
34 - @handler MiniArticleBackupSearch  
35 - post /article_backup/search (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)  
36 -  
37 @doc "小程序获取我发布的文章" 33 @doc "小程序获取我发布的文章"
38 @handler MiniArticleSearchMe 34 @handler MiniArticleSearchMe
39 - post /article/search/me (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse) 35 + post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
  36 +
  37 + @doc "小程序获取文章的编辑记录"
  38 + @handler MiniArticleBackupSearch
  39 + post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse)
40 40
41 } 41 }
42 42
@@ -135,14 +135,15 @@ type ( @@ -135,14 +135,15 @@ type (
135 CompanyId int64 `json:",optional"` // 服务端自动获取 135 CompanyId int64 `json:",optional"` // 服务端自动获取
136 } 136 }
137 MiniArticleBackupSearchResponse { 137 MiniArticleBackupSearchResponse {
138 - Total int `json:"total"` 138 + Total int64 `json:"total"`
139 List []MiniArticleBackupItem `json:"list"` 139 List []MiniArticleBackupItem `json:"list"`
140 } 140 }
141 MiniArticleBackupItem { 141 MiniArticleBackupItem {
142 - Id int `json:"id"` 142 + Id int64 `json:"id"`
  143 + Title string `json:"title"`
143 Content string `json:"content"` 144 Content string `json:"content"`
144 Images []string `json:"images"` 145 Images []string `json:"images"`
145 - CreatedAt int `json:"createdAt"` 146 + CreatedAt int64 `json:"createdAt"`
146 Location Location `json:"location"` 147 Location Location `json:"location"`
147 } 148 }
148 ) 149 )
@@ -13,15 +13,14 @@ import ( @@ -13,15 +13,14 @@ import (
13 13
14 func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 - var req types.MiniArticleSearchMeRequest 16 + var req types.MiniArticleBackupSearchRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 httpx.ErrorCtx(r.Context(), w, err) 18 httpx.ErrorCtx(r.Context(), w, err)
19 return 19 return
20 } 20 }
21 -  
22 - l := article.NewMiniArticleBackupSearchLogic(r.Context(), svcCtx)  
23 token := contextdata.GetUserTokenFromCtx(r.Context()) 21 token := contextdata.GetUserTokenFromCtx(r.Context())
24 req.CompanyId = token.CompanyId 22 req.CompanyId = token.CompanyId
  23 + l := article.NewMiniArticleBackupSearchLogic(r.Context(), svcCtx)
25 resp, err := l.MiniArticleBackupSearch(&req) 24 resp, err := l.MiniArticleBackupSearch(&req)
26 result.HttpResult(r, w, resp, err) 25 result.HttpResult(r, w, resp, err)
27 } 26 }
@@ -199,13 +199,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -199,13 +199,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
199 }, 199 },
200 { 200 {
201 Method: http.MethodPost, 201 Method: http.MethodPost,
202 - Path: "/article_backup/search",  
203 - Handler: article.MiniArticleBackupSearchHandler(serverCtx), 202 + Path: "/article/search/me",
  203 + Handler: article.MiniArticleSearchMeHandler(serverCtx),
204 }, 204 },
205 { 205 {
206 Method: http.MethodPost, 206 Method: http.MethodPost,
207 - Path: "/article/search/me",  
208 - Handler: article.MiniArticleSearchMeHandler(serverCtx), 207 + Path: "/article_backup/search",
  208 + Handler: article.MiniArticleBackupSearchHandler(serverCtx),
209 }, 209 },
210 }, 210 },
211 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 211 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
@@ -2,9 +2,12 @@ package article @@ -2,9 +2,12 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "strings"
5 6
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/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
8 11
9 "github.com/zeromicro/go-zero/core/logx" 12 "github.com/zeromicro/go-zero/core/logx"
10 ) 13 )
@@ -23,8 +26,44 @@ func NewMiniArticleBackupSearchLogic(ctx context.Context, svcCtx *svc.ServiceCon @@ -23,8 +26,44 @@ func NewMiniArticleBackupSearchLogic(ctx context.Context, svcCtx *svc.ServiceCon
23 } 26 }
24 } 27 }
25 28
26 -func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {  
27 - // todo: add your logic here and delete this line 29 +func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniArticleBackupSearchRequest) (resp *types.MiniArticleBackupSearchResponse, err error) {
  30 + var conn = l.svcCtx.DefaultDBConn()
28 31
29 - return 32 + queryOption := domain.NewQueryOptions().
  33 + WithOffsetLimit(req.Page, req.Size).
  34 + MustWithKV("article_id", req.ArticleId).
  35 + MustWithKV("company_id", req.CompanyId)
  36 +
  37 + cnt, backupList, err := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption)
  38 + if err != nil {
  39 + return &types.MiniArticleBackupSearchResponse{}, xerr.NewErrMsgErr("获取编辑记录列表失败", err)
  40 + }
  41 +
  42 + resp = &types.MiniArticleBackupSearchResponse{
  43 + Total: cnt,
  44 + List: make([]types.MiniArticleBackupItem, len(backupList)),
  45 + }
  46 + for i := range backupList {
  47 + content := strings.Builder{}
  48 + for _, val2 := range backupList[i].Section {
  49 + content.WriteString(val2.Content)
  50 + }
  51 + images := []string{}
  52 + for _, val2 := range backupList[i].Images {
  53 + images = append(images, val2.Url)
  54 + }
  55 + resp.List[i] = types.MiniArticleBackupItem{
  56 + Id: backupList[i].Id,
  57 + Title: backupList[i].Title,
  58 + Content: content.String(),
  59 + Images: images,
  60 + CreatedAt: backupList[i].CreatedAt,
  61 + Location: types.Location{
  62 + Longitude: backupList[i].Location.Longitude,
  63 + Latitude: backupList[i].Location.Latitude,
  64 + Descript: backupList[i].Location.Descript,
  65 + },
  66 + }
  67 + }
  68 + return resp, nil
30 } 69 }
@@ -168,6 +168,20 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -168,6 +168,20 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
168 if len(whoRead) > 0 { 168 if len(whoRead) > 0 {
169 newArticle.TargetUser = domain.ArticleTargetLimit 169 newArticle.TargetUser = domain.ArticleTargetLimit
170 } 170 }
  171 + //设置内容概要
  172 + if len(sectionList) > 0 {
  173 + // 截取内容 30个字
  174 + runeNumber := 0 //字数
  175 + stringIndex := 0 //字符串长度
  176 + for i := range sectionList[0].Content {
  177 + if runeNumber > 30 {
  178 + break
  179 + }
  180 + runeNumber += 1
  181 + stringIndex = i
  182 + }
  183 + newArticle.Summary = sectionList[0].Content[0:stringIndex]
  184 + }
171 185
172 err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { 186 err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
173 newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle) 187 newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
@@ -392,15 +392,16 @@ type MiniArticleBackupSearchRequest struct { @@ -392,15 +392,16 @@ type MiniArticleBackupSearchRequest struct {
392 } 392 }
393 393
394 type MiniArticleBackupSearchResponse struct { 394 type MiniArticleBackupSearchResponse struct {
395 - Total int `json:"total"` 395 + Total int64 `json:"total"`
396 List []MiniArticleBackupItem `json:"list"` 396 List []MiniArticleBackupItem `json:"list"`
397 } 397 }
398 398
399 type MiniArticleBackupItem struct { 399 type MiniArticleBackupItem struct {
400 - Id int `json:"id"` 400 + Id int64 `json:"id"`
  401 + Title string `json:"title"`
401 Content string `json:"content"` 402 Content string `json:"content"`
402 Images []string `json:"images"` 403 Images []string `json:"images"`
403 - CreatedAt int `json:"createdAt"` 404 + CreatedAt int64 `json:"createdAt"`
404 Location Location `json:"location"` 405 Location Location `json:"location"`
405 } 406 }
406 407
@@ -30,6 +30,7 @@ type Article struct { @@ -30,6 +30,7 @@ type Article struct {
30 CountComment int // 评论数量 30 CountComment int // 评论数量
31 Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签 31 Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
32 Show int // 评论的展示状态(0显示、1不显示) 32 Show int // 评论的展示状态(0显示、1不显示)
  33 + Summary string // 内容概要
33 } 34 }
34 35
35 func (m *Article) TableName() string { 36 func (m *Article) TableName() string {
@@ -17,7 +17,8 @@ type ArticleBackup struct { @@ -17,7 +17,8 @@ type ArticleBackup struct {
17 DeletedAt int64 17 DeletedAt int64
18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` 18 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
19 Version int 19 Version int
20 - Operator domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 操作人 20 + Operator domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 操作人
  21 + ArticleId int64
21 Title string // 标题 22 Title string // 标题
22 Section []domain.ArticleSection `gorm:"type:jsonb;serializer:json"` // 分段内容 23 Section []domain.ArticleSection `gorm:"type:jsonb;serializer:json"` // 分段内容
23 Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片 24 Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
@@ -25,6 +26,7 @@ type ArticleBackup struct { @@ -25,6 +26,7 @@ type ArticleBackup struct {
25 WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看 26 WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
26 WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人 27 WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
27 Tags []int64 `gorm:"type:jsonb;serializer:json"` // 标签 28 Tags []int64 `gorm:"type:jsonb;serializer:json"` // 标签
  29 + Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
28 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人 30 TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
29 } 31 }
30 32
@@ -149,14 +149,16 @@ func (repository *ArticleBackupRepository) ModelToDomainModel(from *models.Artic @@ -149,14 +149,16 @@ func (repository *ArticleBackupRepository) ModelToDomainModel(from *models.Artic
149 DeletedAt: from.DeletedAt, 149 DeletedAt: from.DeletedAt,
150 Version: from.Version, 150 Version: from.Version,
151 Operator: from.Operator, 151 Operator: from.Operator,
  152 + ArticleId: from.ArticleId,
152 Title: from.Title, 153 Title: from.Title,
153 Section: from.Section, 154 Section: from.Section,
154 Images: from.Images, 155 Images: from.Images,
155 Action: from.Action, 156 Action: from.Action,
  157 + TargetUser: domain.ArticleTarget(from.TargetUser),
  158 + Location: from.Location,
156 WhoRead: from.WhoRead, 159 WhoRead: from.WhoRead,
157 WhoReview: from.WhoReview, 160 WhoReview: from.WhoReview,
158 Tags: from.Tags, 161 Tags: from.Tags,
159 - TargetUser: domain.ArticleTarget(from.TargetUser),  
160 } 162 }
161 // err := copier.Copy(to, from) 163 // err := copier.Copy(to, from)
162 return to, nil 164 return to, nil
@@ -169,14 +171,17 @@ func (repository *ArticleBackupRepository) DomainModelToModel(from *domain.Artic @@ -169,14 +171,17 @@ func (repository *ArticleBackupRepository) DomainModelToModel(from *domain.Artic
169 CreatedAt: from.CreatedAt, 171 CreatedAt: from.CreatedAt,
170 UpdatedAt: from.CreatedAt, 172 UpdatedAt: from.CreatedAt,
171 DeletedAt: from.DeletedAt, 173 DeletedAt: from.DeletedAt,
  174 + IsDel: 0,
172 Version: from.Version, 175 Version: from.Version,
173 Operator: from.Operator, 176 Operator: from.Operator,
  177 + ArticleId: from.ArticleId,
174 Title: from.Title, 178 Title: from.Title,
175 Section: from.Section, 179 Section: from.Section,
176 Images: from.Images, 180 Images: from.Images,
177 Action: from.Action, 181 Action: from.Action,
178 WhoRead: from.WhoRead, 182 WhoRead: from.WhoRead,
179 WhoReview: from.WhoReview, 183 WhoReview: from.WhoReview,
  184 + Location: from.Location,
180 Tags: from.Tags, 185 Tags: from.Tags,
181 TargetUser: int(from.TargetUser), 186 TargetUser: int(from.TargetUser),
182 } 187 }
@@ -169,6 +169,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* @@ -169,6 +169,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
169 CountRead: from.CountRead, 169 CountRead: from.CountRead,
170 Show: domain.ArticleShow(from.Show), 170 Show: domain.ArticleShow(from.Show),
171 Tags: from.Tags, 171 Tags: from.Tags,
  172 + Summary: from.Summary,
172 } 173 }
173 return to, nil 174 return to, nil
174 } 175 }
@@ -195,6 +196,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* @@ -195,6 +196,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
195 CountComment: from.CountComment, 196 CountComment: from.CountComment,
196 Show: int(from.Show), 197 Show: int(from.Show),
197 Tags: from.Tags, 198 Tags: from.Tags,
  199 + Summary: from.Summary,
198 } 200 }
199 // err := copier.Copy(to, from) 201 // err := copier.Copy(to, from)
200 return to, nil 202 return to, nil
@@ -27,6 +27,7 @@ type Article struct { @@ -27,6 +27,7 @@ type Article struct {
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 + Summary string `json:"summary"` // 内容概要
30 // ...more 31 // ...more
31 } 32 }
32 33
@@ -87,6 +88,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art @@ -87,6 +88,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art
87 DeletedAt: 0, 88 DeletedAt: 0,
88 Version: 0, 89 Version: 0,
89 Operator: operator, 90 Operator: operator,
  91 + ArticleId: m.Id,
90 Title: m.Title, 92 Title: m.Title,
91 Section: section, 93 Section: section,
92 Images: m.Images, 94 Images: m.Images,
@@ -14,12 +14,14 @@ type ArticleBackup struct { @@ -14,12 +14,14 @@ type ArticleBackup struct {
14 UpdatedAt int64 `json:"updatedAt,omitempty"` 14 UpdatedAt int64 `json:"updatedAt,omitempty"`
15 DeletedAt int64 `json:"deletedAt,omitempty"` 15 DeletedAt int64 `json:"deletedAt,omitempty"`
16 Version int `json:"version,omitempty"` 16 Version int `json:"version,omitempty"`
17 - Operator UserSimple `json:"operator"` // 操作人 17 + Operator UserSimple `json:"operator"` // 操作人
  18 + ArticleId int64 `json:"articleId"`
18 Title string `json:"title"` // 标题 19 Title string `json:"title"` // 标题
19 Section []ArticleSection `json:"section"` // 分段内容 20 Section []ArticleSection `json:"section"` // 分段内容
20 Images []Image `json:"images"` // 图片 21 Images []Image `json:"images"` // 图片
21 Action string `json:"action"` // 操作 22 Action string `json:"action"` // 操作
22 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人 23 TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
  24 + Location Location `json:"location"` // 定位坐标
23 WhoRead []int64 `json:"whoRead"` // 谁可以看 25 WhoRead []int64 `json:"whoRead"` // 谁可以看
24 WhoReview []int64 `json:"whoReview"` // 评论人 26 WhoReview []int64 `json:"whoReview"` // 评论人
25 Tags []int64 `json:"tags"` // 标签 27 Tags []int64 `json:"tags"` // 标签