作者 郑周

1. 增加消息路由

import "core/comment.api"
\ No newline at end of file
import "core/comment.api"
import "core/message.api"
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "消息中心"
desc: "消息中心"
author: "zz"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: message
jwt: MiniAuth
)
service Core {
@doc "系统消息"
@handler miniSystem
post /mini/message/system (MessageSystemRequest) returns (MessageBusinessResponse)
@doc "业务消息"
@handler miniBusiness
post /mini/message/business (MessageBusinessRequest) returns (MessageBusinessResponse)
}
type (
MessageSystemRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
MessageSystemResponse {
List []MessageSystemItem `json:"list"`
Total int64 `json:"total"`
}
MessageSystemItem struct {
Id int64 `json:"id"` // ID
Type int `json:"type"` // 系统分类
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
}
MessageBusinessRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
MessageBusinessResponse {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
}
MessageBusinessItem struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"` // 公司ID
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
TriggerId int64 `json:"triggerId"` // 触发者ID
RecipientId int64 `json:"recipientId"` // 接收者ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
UserTrigger User `json:"userTrigger"` // 触发者
}
User struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Name string `json:"name,omitempty"` // 名称
Avatar string `json:"avatar,omitempty"` // 头像
Position string `json:"position,omitempty"` // 职位
}
)
... ...
package message
import (
"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 MiniBusinessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageBusinessRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := message.NewMiniBusinessLogic(r.Context(), svcCtx)
resp, err := l.MiniBusiness(&req)
//result.HttpResult(r, w, resp, err)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package message
import (
"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 MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MessageSystemRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := message.NewMiniSystemLogic(r.Context(), svcCtx)
resp, err := l.MiniSystem(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"net/http"
comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment"
message "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
... ... @@ -34,4 +35,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/message/system",
Handler: message.MiniSystemHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/business",
Handler: message.MiniBusinessHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
}
... ...
package message
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniBusinessLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniBusinessLogic {
return &MiniBusinessLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package message
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniSystemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSystemLogic {
return &MiniSystemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageBusinessResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -9,6 +9,56 @@ type CommentResposne struct {
}
type Comment struct {
Id int64 `json:"id"`
Content string `json:"content"`
}
type MessageSystemRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type MessageSystemResponse struct {
List []MessageSystemItem `json:"list"`
Total int64 `json:"total"`
}
type MessageSystemItem struct {
Id int64 `json:"id"` // ID
Type int `json:"type"` // 系统分类
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
}
type MessageBusinessRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type MessageBusinessResponse struct {
List []MessageBusinessItem `json:"list"`
Total int64 `json:"total"`
}
type MessageBusinessItem struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"` // 公司ID
Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
TriggerId int64 `json:"triggerId"` // 触发者ID
RecipientId int64 `json:"recipientId"` // 接收者ID
ArticleId int64 `json:"articleId"` // 文章ID
CommentId int64 `json:"commentId"` // 评论ID
DiscussionId int64 `json:"discussionId"` // 圆桌ID
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
UserTrigger User `json:"userTrigger"` // 触发者
}
type User struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Name string `json:"name,omitempty"` // 名称
Avatar string `json:"avatar,omitempty"` // 头像
Position string `json:"position,omitempty"` // 职位
}
... ...
... ... @@ -23,6 +23,21 @@ type MessageBusiness struct {
Version int `json:",omitempty"`
}
type MsgBusinessType int
type MsgBusinessOpt int
const (
MsgTypeReply MsgBusinessType = 1 // 消息分类-回复
MsgTypeLike MsgBusinessType = 2 // 消息分类-点赞
MsgTypeAccept MsgBusinessType = 3 // 消息分类-被采纳
)
const (
OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论
OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
)
type MessageBusinessRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error)
Update(ctx context.Context, conn transaction.Conn, dm *MessageBusiness) (*MessageBusiness, error)
... ...
... ... @@ -18,6 +18,13 @@ type MessageSystem struct {
Version int `json:",omitempty"`
}
type MsgSystemType int
const (
MsgTypeNormal MsgSystemType = 0
MsgTypeAbnormal MsgSystemType = 1
)
type MessageSystemRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error)
Update(ctx context.Context, conn transaction.Conn, dm *MessageSystem) (*MessageSystem, error)
... ...