作者 tangxvhui

调整接口

@@ -70,7 +70,7 @@ type ( @@ -70,7 +70,7 @@ type (
70 type ( 70 type (
71 MiniArticleGetRequest { 71 MiniArticleGetRequest {
72 Id int64 `path:"id"` //id 72 Id int64 `path:"id"` //id
73 - CompanyId int64 `path:"-"` 73 + CompanyId int64 `path:",optional"`
74 } 74 }
75 MiniArticleGetResponse { 75 MiniArticleGetResponse {
76 Id int64 `json:"id"` //id 76 Id int64 `json:"id"` //id
@@ -99,8 +99,8 @@ type ( @@ -99,8 +99,8 @@ type (
99 // 获取我的发文章记录 99 // 获取我的发文章记录
100 type ( 100 type (
101 MiniArticleSearchMeRequest { 101 MiniArticleSearchMeRequest {
102 - AuthorId int64 `json:"-"`  
103 - CompanyId int64 `json:"-"` 102 + AuthorId int64 `json:",optional"`
  103 + CompanyId int64 `json:",optional"`
104 Page int `json:"page"` 104 Page int `json:"page"`
105 Size int `json:"size"` 105 Size int `json:"size"`
106 } 106 }
@@ -125,7 +125,7 @@ type ( @@ -125,7 +125,7 @@ type (
125 type ( 125 type (
126 MiniUserLikeArticleRequest { 126 MiniUserLikeArticleRequest {
127 ArticleId int64 `json:"articleId"` // 文章id 127 ArticleId int64 `json:"articleId"` // 文章id
128 - CompanyId int64 `json:"-"` //公司id 128 + CompanyId int64 `json:",optional"` //公司id
129 Page int `json:"page"` //分页,第几页 129 Page int `json:"page"` //分页,第几页
130 Size int `json:"size"` //分页,每页几条 130 Size int `json:"size"` //分页,每页几条
131 } 131 }
@@ -147,7 +147,7 @@ type ( @@ -147,7 +147,7 @@ type (
147 MiniSetUserLikeRequset { 147 MiniSetUserLikeRequset {
148 ArticleId int64 `json:"articleId"` //文章id 148 ArticleId int64 `json:"articleId"` //文章id
149 CommentId int64 `json:"commentId"` //评论id 149 CommentId int64 `json:"commentId"` //评论id
150 - UserId int64 `json:"-"` //操作人 150 + UserId int64 `json:",optional"` //操作人
151 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 151 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
152 } 152 }
153 MiniSetUserLikeResponse { 153 MiniSetUserLikeResponse {
@@ -3,7 +3,7 @@ Host: 0.0.0.0 @@ -3,7 +3,7 @@ Host: 0.0.0.0
3 Port: 8081 3 Port: 8081
4 Verbose: true 4 Verbose: true
5 Migrate: false 5 Migrate: false
6 - 6 +Timeout: 30000
7 Log: 7 Log:
8 #Mode: file 8 #Mode: file
9 Encoding: plain 9 Encoding: plain
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
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 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
11 ) 12 )
12 13
13 func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -23,10 +24,6 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -23,10 +24,6 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 req.AuthorId = token.UserId 24 req.AuthorId = token.UserId
24 req.CompanyId = token.CompanyId 25 req.CompanyId = token.CompanyId
25 resp, err := l.MiniArticleSearchMe(&req) 26 resp, err := l.MiniArticleSearchMe(&req)
26 - if err != nil {  
27 - httpx.ErrorCtx(r.Context(), w, err)  
28 - } else {  
29 - httpx.OkJsonCtx(r.Context(), w, resp)  
30 - } 27 + result.HttpResult(r, w, resp, err)
31 } 28 }
32 } 29 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
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 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
11 ) 12 )
12 13
13 func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -22,10 +23,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -22,10 +23,7 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
22 l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx) 23 l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
23 req.AuthorId = token.UserId 24 req.AuthorId = token.UserId
24 resp, err := l.MiniCreateArticle(&req) 25 resp, err := l.MiniCreateArticle(&req)
25 - if err != nil {  
26 - httpx.ErrorCtx(r.Context(), w, err)  
27 - } else {  
28 - httpx.OkJsonCtx(r.Context(), w, resp)  
29 - } 26 + result.HttpResult(r, w, resp, err)
  27 +
30 } 28 }
31 } 29 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
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 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
11 ) 12 )
12 13
13 func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -22,10 +23,6 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -22,10 +23,6 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
22 token := contextdata.GetUserTokenFromCtx(r.Context()) 23 token := contextdata.GetUserTokenFromCtx(r.Context())
23 req.CompanyId = token.CompanyId 24 req.CompanyId = token.CompanyId
24 resp, err := l.MiniGetArticle(&req) 25 resp, err := l.MiniGetArticle(&req)
25 - if err != nil {  
26 - httpx.ErrorCtx(r.Context(), w, err)  
27 - } else {  
28 - httpx.OkJsonCtx(r.Context(), w, resp)  
29 - } 26 + result.HttpResult(r, w, resp, err)
30 } 27 }
31 } 28 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
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 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
11 ) 12 )
12 13
13 func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -22,10 +23,6 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -22,10 +23,6 @@ func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
22 token := contextdata.GetUserTokenFromCtx(r.Context()) 23 token := contextdata.GetUserTokenFromCtx(r.Context())
23 req.UserId = token.UserId 24 req.UserId = token.UserId
24 resp, err := l.MiniSetUserLike(&req) 25 resp, err := l.MiniSetUserLike(&req)
25 - if err != nil {  
26 - httpx.ErrorCtx(r.Context(), w, err)  
27 - } else {  
28 - httpx.OkJsonCtx(r.Context(), w, resp)  
29 - } 26 + result.HttpResult(r, w, resp, err)
30 } 27 }
31 } 28 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
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 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
11 ) 12 )
12 13
13 func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -22,10 +23,6 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -22,10 +23,6 @@ func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
22 token := contextdata.GetUserTokenFromCtx(r.Context()) 23 token := contextdata.GetUserTokenFromCtx(r.Context())
23 req.CompanyId = token.CompanyId 24 req.CompanyId = token.CompanyId
24 resp, err := l.MiniUserLikeArticle(&req) 25 resp, err := l.MiniUserLikeArticle(&req)
25 - if err != nil {  
26 - httpx.ErrorCtx(r.Context(), w, err)  
27 - } else {  
28 - httpx.OkJsonCtx(r.Context(), w, resp)  
29 - } 26 + result.HttpResult(r, w, resp, err)
30 } 27 }
31 } 28 }
@@ -183,11 +183,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -183,11 +183,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
183 Handler: article.MiniCreateArticleHandler(serverCtx), 183 Handler: article.MiniCreateArticleHandler(serverCtx),
184 }, 184 },
185 { 185 {
186 - Method: http.MethodPost,  
187 - Path: "/article/search/me",  
188 - Handler: article.MiniArticleSearchMeHandler(serverCtx),  
189 - },  
190 - {  
191 Method: http.MethodGet, 186 Method: http.MethodGet,
192 Path: "/article/:id", 187 Path: "/article/:id",
193 Handler: article.MiniGetArticleHandler(serverCtx), 188 Handler: article.MiniGetArticleHandler(serverCtx),
@@ -202,6 +197,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -202,6 +197,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
202 Path: "/article/user_like/set", 197 Path: "/article/user_like/set",
203 Handler: article.MiniSetUserLikeHandler(serverCtx), 198 Handler: article.MiniSetUserLikeHandler(serverCtx),
204 }, 199 },
  200 + {
  201 + Method: http.MethodPost,
  202 + Path: "/article/search/me",
  203 + Handler: article.MiniArticleSearchMeHandler(serverCtx),
  204 + },
205 }, 205 },
206 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 206 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
207 rest.WithPrefix("/v1/mini"), 207 rest.WithPrefix("/v1/mini"),
@@ -35,7 +35,10 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -35,7 +35,10 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
35 if err != nil { 35 if err != nil {
36 return nil, xerr.NewErrMsgErr("创建文章内容失败", err) 36 return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
37 } 37 }
38 - //TODO 获取人员信息 38 + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, author.CompanyId)
  39 + if err != nil {
  40 + return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
  41 + }
39 articleAuthor := domain.UserSimple{ 42 articleAuthor := domain.UserSimple{
40 Id: author.Id, 43 Id: author.Id,
41 Name: author.Name, 44 Name: author.Name,
@@ -43,9 +46,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -43,9 +46,16 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
43 GroupId: 0, 46 GroupId: 0,
44 Group: "", 47 Group: "",
45 Position: author.Position, 48 Position: author.Position,
46 - Company: "", 49 + Company: companyInfo.Name,
47 CompanyId: author.CompanyId, 50 CompanyId: author.CompanyId,
48 } 51 }
  52 + if author.DepartmentId > 0 {
  53 + department, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, author.DepartmentId)
  54 + if err == nil {
  55 + articleAuthor.GroupId = department.Id
  56 + articleAuthor.Group = department.Name
  57 + }
  58 + }
49 if len(req.Images) > 9 { 59 if len(req.Images) > 9 {
50 return nil, xerr.NewErrMsg("图片数量最多9张") 60 return nil, xerr.NewErrMsg("图片数量最多9张")
51 } 61 }
@@ -76,10 +86,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -76,10 +86,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
76 } 86 }
77 //检查文章可被哪些人评论 87 //检查文章可被哪些人评论
78 whoReview := []int64{} 88 whoReview := []int64{}
  89 + if len(req.WhoReview) > 0 {
  90 + whoReview = lo.Uniq(req.WhoReview)
  91 + }
79 //有指定可查看人的情况 92 //有指定可查看人的情况
80 if len(whoRead) > 0 { 93 if len(whoRead) > 0 {
81 if len(whoReview) > 0 { 94 if len(whoReview) > 0 {
82 - whoReview = lo.Uniq(req.WhoReview)  
83 // 检查 whoRead 是否 完全包含 whoReview 95 // 检查 whoRead 是否 完全包含 whoReview
84 ok := lo.Every(whoRead, whoReview) 96 ok := lo.Every(whoRead, whoReview)
85 if !ok { 97 if !ok {
@@ -247,7 +247,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ @@ -247,7 +247,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
247 return nil, xerr.NewErrMsgErr("设置点赞标识失败", err) 247 return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
248 } 248 }
249 articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId) 249 articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
250 - if err == nil { 250 + if err != nil {
251 return nil, xerr.NewErrMsgErr("获取点赞数量失败", err) 251 return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
252 } 252 }
253 resp = &types.MiniSetUserLikeResponse{ 253 resp = &types.MiniSetUserLikeResponse{
@@ -301,7 +301,7 @@ type MiniArticleCreateResponse struct { @@ -301,7 +301,7 @@ type MiniArticleCreateResponse struct {
301 301
302 type MiniArticleGetRequest struct { 302 type MiniArticleGetRequest struct {
303 Id int64 `path:"id"` //id 303 Id int64 `path:"id"` //id
304 - CompanyId int64 `path:"-"` 304 + CompanyId int64 `path:",optional"`
305 } 305 }
306 306
307 type MiniArticleGetResponse struct { 307 type MiniArticleGetResponse struct {
@@ -329,8 +329,8 @@ type ArticleSection struct { @@ -329,8 +329,8 @@ type ArticleSection struct {
329 } 329 }
330 330
331 type MiniArticleSearchMeRequest struct { 331 type MiniArticleSearchMeRequest struct {
332 - AuthorId int64 `json:"-"`  
333 - CompanyId int64 `json:"-"` 332 + AuthorId int64 `json:",optional"`
  333 + CompanyId int64 `json:",optional"`
334 Page int `json:"page"` 334 Page int `json:"page"`
335 Size int `json:"size"` 335 Size int `json:"size"`
336 } 336 }
@@ -352,7 +352,7 @@ type ArticleSearchMe struct { @@ -352,7 +352,7 @@ type ArticleSearchMe struct {
352 352
353 type MiniUserLikeArticleRequest struct { 353 type MiniUserLikeArticleRequest struct {
354 ArticleId int64 `json:"articleId"` // 文章id 354 ArticleId int64 `json:"articleId"` // 文章id
355 - CompanyId int64 `json:"-"` //公司id 355 + CompanyId int64 `json:",optional"` //公司id
356 Page int `json:"page"` //分页,第几页 356 Page int `json:"page"` //分页,第几页
357 Size int `json:"size"` //分页,每页几条 357 Size int `json:"size"` //分页,每页几条
358 } 358 }
@@ -373,7 +373,7 @@ type WhichUserLikeArticle struct { @@ -373,7 +373,7 @@ type WhichUserLikeArticle struct {
373 type MiniSetUserLikeRequset struct { 373 type MiniSetUserLikeRequset struct {
374 ArticleId int64 `json:"articleId"` //文章id 374 ArticleId int64 `json:"articleId"` //文章id
375 CommentId int64 `json:"commentId"` //评论id 375 CommentId int64 `json:"commentId"` //评论id
376 - UserId int64 `json:"-"` //操作人 376 + UserId int64 `json:",optional"` //操作人
377 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 377 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
378 } 378 }
379 379