作者 郑周

1 消息区分 点赞 和 评论消息

@@ -16,15 +16,19 @@ info( @@ -16,15 +16,19 @@ info(
16 service Core { 16 service Core {
17 @doc "系统消息" 17 @doc "系统消息"
18 @handler miniSystem 18 @handler miniSystem
19 - post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse) 19 + post /mini/message/system (MessageRequest) returns (MessageSystemResponse)
20 20
21 - @doc "业务消息"  
22 - @handler miniBusiness  
23 - post /mini/message/business (MessageBusinessRequest) returns (MessageBusinessResponse) 21 + @doc "评论消息"
  22 + @handler miniComment
  23 + post /mini/message/comment (MessageRequest) returns (MessageBusinessResponse)
  24 +
  25 + @doc "点赞消息"
  26 + @handler miniLike
  27 + post /mini/message/like (MessageRequest) returns (MessageBusinessResponse)
24 } 28 }
25 29
26 type ( 30 type (
27 - MessageSystemRequest { 31 + MessageRequest {
28 Page int `json:"page"` 32 Page int `json:"page"`
29 Size int `json:"size"` 33 Size int `json:"size"`
30 } 34 }
@@ -40,11 +44,6 @@ type ( @@ -40,11 +44,6 @@ type (
40 CreatedAt int64 `json:"createdAt"` // 创建时间 44 CreatedAt int64 `json:"createdAt"` // 创建时间
41 } 45 }
42 46
43 - MessageBusinessRequest {  
44 - Type int `json:"type"`  
45 - Page int `json:"page"`  
46 - Size int `json:"size"`  
47 - }  
48 MessageBusinessResponse { 47 MessageBusinessResponse {
49 List []MessageBusinessItem `json:"list"` 48 List []MessageBusinessItem `json:"list"`
50 Total int64 `json:"total"` 49 Total int64 `json:"total"`
1 package message 1 package message
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
4 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" 5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
5 "net/http" 6 "net/http"
6 7
@@ -10,16 +11,16 @@ import ( @@ -10,16 +11,16 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
11 ) 12 )
12 13
13 -func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 +func MiniCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
14 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
15 - var req types.MessageBusinessRequest 16 + var req types.MessageRequest
16 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
17 result.ParamErrorResult(r, w, err) 18 result.ParamErrorResult(r, w, err)
18 return 19 return
19 } 20 }
20 21
21 l := message.NewMiniBusinessLogic(r.Context(), svcCtx) 22 l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
22 - resp, err := l.MiniBusiness(&req) 23 + resp, err := l.MiniBusiness(&req, domain.MsgTypeReply)
23 result.HttpResult(r, w, resp, err) 24 result.HttpResult(r, w, resp, err)
24 } 25 }
25 } 26 }
  1 +package message
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  6 + "net/http"
  7 +
  8 + "github.com/zeromicro/go-zero/rest/httpx"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  12 +)
  13 +
  14 +func MiniLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  15 + return func(w http.ResponseWriter, r *http.Request) {
  16 + var req types.MessageRequest
  17 + if err := httpx.Parse(r, &req); err != nil {
  18 + result.ParamErrorResult(r, w, err)
  19 + return
  20 + }
  21 +
  22 + l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
  23 + resp, err := l.MiniBusiness(&req, domain.MsgTypeLike)
  24 + result.HttpResult(r, w, resp, err)
  25 + }
  26 +}
@@ -12,7 +12,7 @@ import ( @@ -12,7 +12,7 @@ import (
12 12
13 func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 13 func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
14 return func(w http.ResponseWriter, r *http.Request) { 14 return func(w http.ResponseWriter, r *http.Request) {
15 - var req types.MessageSystemRequest 15 + var req types.MessageRequest
16 if err := httpx.Parse(r, &req); err != nil { 16 if err := httpx.Parse(r, &req); err != nil {
17 result.ParamErrorResult(r, w, err) 17 result.ParamErrorResult(r, w, err)
18 return 18 return
@@ -116,8 +116,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -116,8 +116,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
116 }, 116 },
117 { 117 {
118 Method: http.MethodPost, 118 Method: http.MethodPost,
119 - Path: "/mini/message/business",  
120 - Handler: message.MiniBusinessHandler(serverCtx), 119 + Path: "/mini/message/comment",
  120 + Handler: message.MiniCommentHandler(serverCtx),
  121 + },
  122 + {
  123 + Method: http.MethodPost,
  124 + Path: "/mini/message/like",
  125 + Handler: message.MiniLikeHandler(serverCtx),
121 }, 126 },
122 }, 127 },
123 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 128 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
@@ -26,10 +26,9 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini @@ -26,10 +26,9 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
26 } 26 }
27 } 27 }
28 28
29 -func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) { 29 +func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType domain.MsgBusinessType) (resp *types.MessageBusinessResponse, err error) {
30 var userToken = contextdata.GetUserTokenFromCtx(l.ctx) 30 var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
31 var conn = l.svcCtx.DefaultDBConn() 31 var conn = l.svcCtx.DefaultDBConn()
32 - var msgType = req.Type  
33 32
34 total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions(). 33 total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
35 WithOffsetLimit(req.Page, req.Size). 34 WithOffsetLimit(req.Page, req.Size).
@@ -100,8 +99,8 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -100,8 +99,8 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
100 if len(companyIds) > 0 { 99 if len(companyIds) > 0 {
101 _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions(). 100 _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
102 WithFindOnly(). 101 WithFindOnly().
103 - WithKV("ids", userIds).  
104 - WithKV("limit", len(userIds))) 102 + WithKV("ids", companyIds).
  103 + WithKV("limit", len(companyIds)))
105 if err != nil { 104 if err != nil {
106 return nil, err 105 return nil, err
107 } 106 }
@@ -25,7 +25,7 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy @@ -25,7 +25,7 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy
25 } 25 }
26 } 26 }
27 27
28 -func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) { 28 +func (l *MiniSystemLogic) MiniSystem(req *types.MessageRequest) (resp *types.MessageSystemResponse, err error) {
29 var userToken = contextdata.GetUserTokenFromCtx(l.ctx) 29 var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
30 30
31 total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions(). 31 total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
@@ -179,7 +179,7 @@ type SystemListCommentRequest struct { @@ -179,7 +179,7 @@ type SystemListCommentRequest struct {
179 Page int `json:"page"` 179 Page int `json:"page"`
180 Size int `json:"size"` 180 Size int `json:"size"`
181 CompanyId int64 `json:",optional"` // 181 CompanyId int64 `json:",optional"` //
182 - TopId int64 `json:"topId,optional"` // 评论的顶层ID 182 + TopId int64 `json:"topId,optional"` // 评论的顶层ID
183 FromUser string `json:"fromUser,optional"` // 用户 183 FromUser string `json:"fromUser,optional"` // 用户
184 Show int `json:"show,optional"` // 显示状态 184 Show int `json:"show,optional"` // 显示状态
185 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 185 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
@@ -252,7 +252,7 @@ type SystemEditCommentResponse struct { @@ -252,7 +252,7 @@ type SystemEditCommentResponse struct {
252 Id int64 `json:"id"` 252 Id int64 `json:"id"`
253 } 253 }
254 254
255 -type MessageSystemRequest struct { 255 +type MessageRequest struct {
256 Page int `json:"page"` 256 Page int `json:"page"`
257 Size int `json:"size"` 257 Size int `json:"size"`
258 } 258 }
@@ -270,12 +270,6 @@ type MessageSystemItem struct { @@ -270,12 +270,6 @@ type MessageSystemItem struct {
270 CreatedAt int64 `json:"createdAt"` // 创建时间 270 CreatedAt int64 `json:"createdAt"` // 创建时间
271 } 271 }
272 272
273 -type MessageBusinessRequest struct {  
274 - Type int `json:"type"`  
275 - Page int `json:"page"`  
276 - Size int `json:"size"`  
277 -}  
278 -  
279 type MessageBusinessResponse struct { 273 type MessageBusinessResponse struct {
280 List []MessageBusinessItem `json:"list"` 274 List []MessageBusinessItem `json:"list"`
281 Total int64 `json:"total"` 275 Total int64 `json:"total"`