作者 tangxvhui

草稿箱的操作相关

@@ -52,7 +52,7 @@ service Core { @@ -52,7 +52,7 @@ service Core {
52 @handler MiniGetArticleDraftMe 52 @handler MiniGetArticleDraftMe
53 get /article_draft/me/:id (MiniArticleDraftGetMeRequest) returns (MiniArticleDraftGetMeResponse) 53 get /article_draft/me/:id (MiniArticleDraftGetMeRequest) returns (MiniArticleDraftGetMeResponse)
54 54
55 - @doc "小程序获取我的草稿内容" 55 + @doc "小程序删除我的草稿内容"
56 @handler MiniDeleteArticleDraftMe 56 @handler MiniDeleteArticleDraftMe
57 delete /article_draft/me/:id (MiniArticleDraftDeleteMeRequest) returns (MiniArticleDraftDeleteMeResponse) 57 delete /article_draft/me/:id (MiniArticleDraftDeleteMeRequest) returns (MiniArticleDraftDeleteMeResponse)
58 58
@@ -213,21 +213,21 @@ type ( @@ -213,21 +213,21 @@ type (
213 List []MiniArticleDraftItem `json:"list"` 213 List []MiniArticleDraftItem `json:"list"`
214 } 214 }
215 MiniArticleDraftItem { 215 MiniArticleDraftItem {
216 - Id int64 `json:"id"`  
217 - Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式  
218 - Content []string `json:"content"` // 填写的内容  
219 - Title string `json:"title"` // 标题  
220 - Images []string `json:"images"` // 图片 216 + Id int64 `json:"id"`
  217 + Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式
  218 + Content []string `json:"content"` // 填写的内容
  219 + Title string `json:"title"` // 标题
  220 + Images []string `json:"images"` // 图片
  221 + CreatedAt int64 `json:"createdAt"`
221 } 222 }
222 ) 223 )
223 224
224 //获取我的草稿内容 225 //获取我的草稿内容
225 type ( 226 type (
226 MiniArticleDraftGetMeRequest { 227 MiniArticleDraftGetMeRequest {
227 - CompanyId int64 `json:",optional"` // 公司id  
228 - AuthorId int64 `json:",optional"` // 发布人  
229 - Page int `json:"page"`  
230 - Size int `json:"size"` 228 + CompanyId int64 `path:",optional"` // 公司id
  229 + AuthorId int64 `path:",optional"` // 发布人
  230 + Id int64 `path:"id"`
231 } 231 }
232 232
233 MiniArticleDraftGetMeResponse { 233 MiniArticleDraftGetMeResponse {
@@ -251,14 +251,7 @@ type ( @@ -251,14 +251,7 @@ type (
251 } 251 }
252 252
253 MiniArticleDraftDeleteMeResponse { 253 MiniArticleDraftDeleteMeResponse {
254 - Id int64 `json:"id"` //  
255 - Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式  
256 - Content []string `json:"content"` // 填写的内容  
257 - Title string `json:"title"` // 标题  
258 - Images []string `json:"images"` // 图片  
259 - WhoRead []int64 `json:"whoRead"` // 谁可以看  
260 - WhoReview []int64 `json:"whoReview"` // 评论人  
261 - Location Location `json:"location"` // 坐标 254 + Id int64 `json:"id"` //
262 } 255 }
263 ) 256 )
264 257
@@ -7,6 +7,8 @@ import ( @@ -7,6 +7,8 @@ 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"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
10 ) 12 )
11 13
12 func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -18,11 +20,10 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -18,11 +20,10 @@ func MiniDeleteArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
18 } 20 }
19 21
20 l := article.NewMiniDeleteArticleDraftMeLogic(r.Context(), svcCtx) 22 l := article.NewMiniDeleteArticleDraftMeLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.AuthorId = token.UserId
  25 + req.CompanyId = token.CompanyId
21 resp, err := l.MiniDeleteArticleDraftMe(&req) 26 resp, err := l.MiniDeleteArticleDraftMe(&req)
22 - if err != nil {  
23 - httpx.ErrorCtx(r.Context(), w, err)  
24 - } else {  
25 - httpx.OkJsonCtx(r.Context(), w, resp)  
26 - } 27 + result.HttpResult(r, w, resp, err)
27 } 28 }
28 } 29 }
@@ -7,6 +7,8 @@ import ( @@ -7,6 +7,8 @@ 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"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
10 ) 12 )
11 13
12 func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -18,11 +20,10 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun @@ -18,11 +20,10 @@ func MiniSearchArticleDraftMeHandler(svcCtx *svc.ServiceContext) http.HandlerFun
18 } 20 }
19 21
20 l := article.NewMiniSearchArticleDraftMeLogic(r.Context(), svcCtx) 22 l := article.NewMiniSearchArticleDraftMeLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.AuthorId = token.UserId
  25 + req.CompanyId = token.CompanyId
21 resp, err := l.MiniSearchArticleDraftMe(&req) 26 resp, err := l.MiniSearchArticleDraftMe(&req)
22 - if err != nil {  
23 - httpx.ErrorCtx(r.Context(), w, err)  
24 - } else {  
25 - httpx.OkJsonCtx(r.Context(), w, resp)  
26 - } 27 + result.HttpResult(r, w, resp, err)
27 } 28 }
28 } 29 }
@@ -83,6 +83,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr @@ -83,6 +83,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr
83 if err != nil { 83 if err != nil {
84 return err 84 return err
85 } 85 }
  86 + //增加浏览计数
86 err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo) 87 err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo)
87 return err 88 return err
88 }, true) 89 }, true)
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ 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/pkg/xerr"
8 9
9 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
10 ) 11 )
@@ -23,8 +24,25 @@ func NewMiniDeleteArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo @@ -23,8 +24,25 @@ func NewMiniDeleteArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo
23 } 24 }
24 } 25 }
25 26
  27 +// 删除我的草稿记录
26 func (l *MiniDeleteArticleDraftMeLogic) MiniDeleteArticleDraftMe(req *types.MiniArticleDraftDeleteMeRequest) (resp *types.MiniArticleDraftDeleteMeResponse, err error) { 28 func (l *MiniDeleteArticleDraftMeLogic) MiniDeleteArticleDraftMe(req *types.MiniArticleDraftDeleteMeRequest) (resp *types.MiniArticleDraftDeleteMeResponse, err error) {
27 - // todo: add your logic here and delete this line 29 + var conn = l.svcCtx.DefaultDBConn()
28 30
29 - return 31 + draftInfo, err := l.svcCtx.ArticleDraftRepository.FindOne(l.ctx, conn, req.Id)
  32 + if err != nil {
  33 + return nil, xerr.NewErrMsgErr("删除草稿失败", err)
  34 + }
  35 + if draftInfo.AuthorId != req.AuthorId {
  36 + if err != nil {
  37 + return nil, xerr.NewErrMsg("删除草稿失败")
  38 + }
  39 + }
  40 + _, err = l.svcCtx.ArticleDraftRepository.Delete(l.ctx, conn, draftInfo)
  41 + if err != nil {
  42 + return nil, xerr.NewErrMsgErr("删除草稿失败", err)
  43 + }
  44 + resp = &types.MiniArticleDraftDeleteMeResponse{
  45 + Id: draftInfo.Id,
  46 + }
  47 + return resp, nil
30 } 48 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ 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/pkg/xerr"
8 9
9 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
10 ) 11 )
@@ -23,8 +24,35 @@ func NewMiniGetArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceConte @@ -23,8 +24,35 @@ func NewMiniGetArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceConte
23 } 24 }
24 } 25 }
25 26
  27 +// 获取我的草稿记录
26 func (l *MiniGetArticleDraftMeLogic) MiniGetArticleDraftMe(req *types.MiniArticleDraftGetMeRequest) (resp *types.MiniArticleDraftGetMeResponse, err error) { 28 func (l *MiniGetArticleDraftMeLogic) MiniGetArticleDraftMe(req *types.MiniArticleDraftGetMeRequest) (resp *types.MiniArticleDraftGetMeResponse, err error) {
27 - // todo: add your logic here and delete this line 29 + var conn = l.svcCtx.DefaultDBConn()
28 30
  31 + draftInfo, err := l.svcCtx.ArticleDraftRepository.FindOne(l.ctx, conn, req.Id)
  32 + if err != nil {
  33 + return nil, xerr.NewErrMsgErr("获取草稿失败", err)
  34 + }
  35 + if draftInfo.AuthorId != req.AuthorId {
  36 + if err != nil {
  37 + return nil, xerr.NewErrMsg("获取草稿失败")
  38 + }
  39 + }
  40 + resp = &types.MiniArticleDraftGetMeResponse{
  41 + Id: draftInfo.Id,
  42 + Template: draftInfo.Template,
  43 + Content: draftInfo.Content,
  44 + Title: draftInfo.Title,
  45 + Images: []string{},
  46 + WhoRead: draftInfo.WhoRead,
  47 + WhoReview: draftInfo.WhoReview,
  48 + Location: types.Location{
  49 + Longitude: draftInfo.Location.Longitude,
  50 + Latitude: draftInfo.Location.Latitude,
  51 + Descript: draftInfo.Location.Descript,
  52 + },
  53 + }
  54 + for _, val := range draftInfo.Images {
  55 + resp.Images = append(resp.Images, val.Url)
  56 + }
29 return 57 return
30 } 58 }
@@ -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 )
@@ -24,7 +26,33 @@ func NewMiniSearchArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo @@ -24,7 +26,33 @@ func NewMiniSearchArticleDraftMeLogic(ctx context.Context, svcCtx *svc.ServiceCo
24 } 26 }
25 27
26 func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.MiniArticleDraftSearchMeRequest) (resp *types.MiniArticleDraftSearchMeResponse, err error) { 28 func (l *MiniSearchArticleDraftMeLogic) MiniSearchArticleDraftMe(req *types.MiniArticleDraftSearchMeRequest) (resp *types.MiniArticleDraftSearchMeResponse, err error) {
27 - // todo: add your logic here and delete this line 29 + var conn = l.svcCtx.DefaultDBConn()
28 30
29 - return 31 + queryOption := domain.NewQueryOptions().
  32 + WithOffsetLimit(req.Page, req.Size).
  33 + MustWithKV("authorId", req.AuthorId)
  34 +
  35 + cnt, draftList, err := l.svcCtx.ArticleDraftRepository.Find(l.ctx, conn, queryOption)
  36 + if err != nil {
  37 + return nil, xerr.NewErrMsgErr("获取草稿列表失败", err)
  38 + }
  39 + resp = &types.MiniArticleDraftSearchMeResponse{
  40 + Total: cnt,
  41 + List: make([]types.MiniArticleDraftItem, len(draftList)),
  42 + }
  43 +
  44 + for i := range draftList {
  45 + images := []string{}
  46 + for _, val := range draftList[i].Images {
  47 + images = append(images, val.Url)
  48 + }
  49 + resp.List[i] = types.MiniArticleDraftItem{
  50 + Id: draftList[i].Id,
  51 + Template: draftList[i].Template,
  52 + Content: draftList[i].Content,
  53 + Title: draftList[i].Title,
  54 + Images: images,
  55 + }
  56 + }
  57 + return resp, nil
30 } 58 }
@@ -233,7 +233,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ @@ -233,7 +233,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
233 CommentAuthor: 0, 233 CommentAuthor: 0,
234 UserId: req.UserId, 234 UserId: req.UserId,
235 } 235 }
236 - // 去除点赞标识 236 + // 添加点赞标识
237 _, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo) 237 _, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo)
238 if err != nil { 238 if err != nil {
239 return err 239 return err
@@ -200,10 +200,9 @@ type MiniArticleDraftItem struct { @@ -200,10 +200,9 @@ type MiniArticleDraftItem struct {
200 } 200 }
201 201
202 type MiniArticleDraftGetMeRequest struct { 202 type MiniArticleDraftGetMeRequest struct {
203 - CompanyId int64 `json:",optional"` // 公司id  
204 - AuthorId int64 `json:",optional"` // 发布人  
205 - Page int `json:"page"`  
206 - Size int `json:"size"` 203 + CompanyId int64 `path:",optional"` // 公司id
  204 + AuthorId int64 `path:",optional"` // 发布人
  205 + Id int64 `path:"id"`
207 } 206 }
208 207
209 type MiniArticleDraftGetMeResponse struct { 208 type MiniArticleDraftGetMeResponse struct {
@@ -224,14 +223,7 @@ type MiniArticleDraftDeleteMeRequest struct { @@ -224,14 +223,7 @@ type MiniArticleDraftDeleteMeRequest struct {
224 } 223 }
225 224
226 type MiniArticleDraftDeleteMeResponse struct { 225 type MiniArticleDraftDeleteMeResponse struct {
227 - Id int64 `json:"id"` //  
228 - Template int `json:"template"` // 使用哪个模板进行编辑 0、无 1、演绎式 2、归纳式  
229 - Content []string `json:"content"` // 填写的内容  
230 - Title string `json:"title"` // 标题  
231 - Images []string `json:"images"` // 图片  
232 - WhoRead []int64 `json:"whoRead"` // 谁可以看  
233 - WhoReview []int64 `json:"whoReview"` // 评论人  
234 - Location Location `json:"location"` // 坐标 226 + Id int64 `json:"id"` //
235 } 227 }
236 228
237 type SystemArticleGetRequest struct { 229 type SystemArticleGetRequest struct {
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 6
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
8 "gorm.io/gorm" 8 "gorm.io/gorm"
  9 + "gorm.io/plugin/soft_delete"
9 ) 10 )
10 11
11 type UserReadArticle struct { 12 type UserReadArticle struct {
@@ -13,6 +14,7 @@ type UserReadArticle struct { @@ -13,6 +14,7 @@ type UserReadArticle struct {
13 CreatedAt int64 14 CreatedAt int64
14 UpdatedAt int64 15 UpdatedAt int64
15 DeletedAt int64 16 DeletedAt int64
  17 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
16 Version int 18 Version int
17 CompanyId int64 19 CompanyId int64
18 UserId int64 20 UserId int64