作者 郑周

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

... ... @@ -16,15 +16,19 @@ info(
service Core {
@doc "系统消息"
@handler miniSystem
post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse)
post /mini/message/system (MessageRequest) returns (MessageSystemResponse)
@doc "业务消息"
@handler miniBusiness
post /mini/message/business (MessageBusinessRequest) returns (MessageBusinessResponse)
@doc "评论消息"
@handler miniComment
post /mini/message/comment (MessageRequest) returns (MessageBusinessResponse)
@doc "点赞消息"
@handler miniLike
post /mini/message/like (MessageRequest) returns (MessageBusinessResponse)
}
type (
MessageSystemRequest {
MessageRequest {
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -40,11 +44,6 @@ type (
CreatedAt int64 `json:"createdAt"` // 创建时间
}
MessageBusinessRequest {
Type int `json:"type"`
Page int `json:"page"`
Size int `json:"size"`
}
MessageBusinessResponse {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
... ...
package message
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
... ... @@ -10,16 +11,16 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func MiniCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageBusinessRequest
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
resp, err := l.MiniBusiness(&req)
resp, err := l.MiniBusiness(&req, domain.MsgTypeReply)
result.HttpResult(r, w, resp, err)
}
}
... ...
package message
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
resp, err := l.MiniBusiness(&req, domain.MsgTypeLike)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -12,7 +12,7 @@ import (
func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageSystemRequest
var req types.MessageRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
... ...
... ... @@ -116,8 +116,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/message/business",
Handler: message.MiniBusinessHandler(serverCtx),
Path: "/mini/message/comment",
Handler: message.MiniCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/like",
Handler: message.MiniLikeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
... ...
... ... @@ -26,10 +26,9 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
}
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType domain.MsgBusinessType) (resp *types.MessageBusinessResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
var msgType = req.Type
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
... ... @@ -100,8 +99,8 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
if len(companyIds) > 0 {
_, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithFindOnly().
WithKV("ids", userIds).
WithKV("limit", len(userIds)))
WithKV("ids", companyIds).
WithKV("limit", len(companyIds)))
if err != nil {
return nil, err
}
... ...
... ... @@ -25,7 +25,7 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy
}
}
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) {
func (l *MiniSystemLogic) MiniSystem(req *types.MessageRequest) (resp *types.MessageSystemResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
... ...
... ... @@ -252,7 +252,7 @@ type SystemEditCommentResponse struct {
Id int64 `json:"id"`
}
type MessageSystemRequest struct {
type MessageRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
... ... @@ -270,12 +270,6 @@ type MessageSystemItem struct {
CreatedAt int64 `json:"createdAt"` // 创建时间
}
type MessageBusinessRequest struct {
Type int `json:"type"`
Page int `json:"page"`
Size int `json:"size"`
}
type MessageBusinessResponse struct {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
... ...