first commit
This commit is contained in:
48
gateway/api/v1/internal/handler/record/focushandler.go
Normal file
48
gateway/api/v1/internal/handler/record/focushandler.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/logic/record"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/api"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
)
|
||||
|
||||
//@Summary 关注消息
|
||||
//@Description
|
||||
//@Author dld@33.cn
|
||||
//@Tags record 消息模块
|
||||
//@Accept json
|
||||
//@Produce json
|
||||
//@Param FZM-SIGNATURE header string true "MOCK"
|
||||
//@Param data body model.FocusMsgReq true "body"
|
||||
//@Success 200 {object} model.GeneralResponse{}
|
||||
//@Router /app/record/focus [post]
|
||||
func FocusHandler(ctx *svc.ServiceContext) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
req := &model.FocusMsgReq{}
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
var err error
|
||||
operator := c.MustGet(api.Address).(string)
|
||||
l := record.NewLogic(c.Request.Context(), ctx)
|
||||
switch req.Type {
|
||||
case model.Private:
|
||||
err = l.FocusPersonal(operator, req.LogId)
|
||||
case model.Group:
|
||||
err = l.FocusGroup(operator, req.LogId)
|
||||
default:
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("undefined type"))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.CodeInnerError).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
c.Set(api.ReqResult, nil)
|
||||
c.Set(api.ReqError, err)
|
||||
}
|
||||
}
|
||||
142
gateway/api/v1/internal/handler/record/pushhandler.go
Normal file
142
gateway/api/v1/internal/handler/record/pushhandler.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/logic/record"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/api"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
comet "gitlab.33.cn/chat/im/api/comet/grpc"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// PushToUid
|
||||
// @Summary 推送消息
|
||||
// @Description comet.Proto由接口组装,客户端只需传入comet.Proto的body部分
|
||||
// @Author dld@33.cn
|
||||
// @Tags record 消息模块
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param FZM-SIGNATURE header string true "MOCK"
|
||||
// @Param message body string true "消息协议序列化"
|
||||
// @Success 200 {object} model.GeneralResponse{}
|
||||
// @Router /record/push [post]
|
||||
func PushToUid(ctx *svc.ServiceContext) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("MultipartForm"+err.Error()))
|
||||
return
|
||||
}
|
||||
files := form.File["message"]
|
||||
|
||||
if len(files) < 1 {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("file len less than 1"))
|
||||
return
|
||||
}
|
||||
|
||||
//file, err := c.FormFile("")
|
||||
file := files[0]
|
||||
f, err := file.Open()
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("Open File"+err.Error()))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("ReadAll"+err.Error()))
|
||||
return
|
||||
}
|
||||
if len(body) == 0 {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("error message length 0"))
|
||||
return
|
||||
}
|
||||
p := comet.Proto{
|
||||
Ver: 1,
|
||||
Op: int32(comet.Op_SendMsg),
|
||||
Seq: 0,
|
||||
Ack: 0,
|
||||
Body: body,
|
||||
}
|
||||
data, err := proto.Marshal(&p)
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.SendMsgFailed).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
uid := c.MustGet(api.Address).(string)
|
||||
l := record.NewLogic(c.Request.Context(), ctx)
|
||||
mid, createTime, err := l.Push("", uid, data)
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.SendMsgFailed).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
ret := map[string]interface{}{
|
||||
"logId": mid,
|
||||
"datetime": createTime,
|
||||
}
|
||||
c.Set(api.ReqResult, ret)
|
||||
c.Set(api.ReqError, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// PushToUid2
|
||||
// @Summary 推送消息2
|
||||
// @Description comet.Proto由客户端传入
|
||||
// @Author dld@33.cn
|
||||
// @Tags record 消息模块
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param FZM-SIGNATURE header string true "MOCK"
|
||||
// @Param message body string true "消息协议序列化"
|
||||
// @Success 200 {object} model.GeneralResponse{}
|
||||
// @Router /record/push2 [post]
|
||||
func PushToUid2(ctx *svc.ServiceContext) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("MultipartForm"+err.Error()))
|
||||
return
|
||||
}
|
||||
files := form.File["message"]
|
||||
|
||||
if len(files) < 1 {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("file len less than 1"))
|
||||
return
|
||||
}
|
||||
|
||||
//file, err := c.FormFile("")
|
||||
file := files[0]
|
||||
f, err := file.Open()
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("Open File"+err.Error()))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("ReadAll"+err.Error()))
|
||||
return
|
||||
}
|
||||
if len(body) == 0 {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("error message length 0"))
|
||||
return
|
||||
}
|
||||
uid := c.MustGet(api.Address).(string)
|
||||
l := record.NewLogic(c.Request.Context(), ctx)
|
||||
mid, createTime, err := l.Push("", uid, body)
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.SendMsgFailed).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
ret := map[string]interface{}{
|
||||
"logId": mid,
|
||||
"datetime": createTime,
|
||||
}
|
||||
c.Set(api.ReqResult, ret)
|
||||
c.Set(api.ReqError, nil)
|
||||
}
|
||||
}
|
||||
46
gateway/api/v1/internal/handler/record/recordhandler.go
Normal file
46
gateway/api/v1/internal/handler/record/recordhandler.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/logic/record"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/api"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
)
|
||||
|
||||
// GetPriRecords
|
||||
// @Summary 获得聊天记录
|
||||
// @Author chy@33.cn
|
||||
// @Tags record 消息模块
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param FZM-SIGNATURE header string true "MOCK"
|
||||
// @Param data body model.GetPriRecordsReq false "body"
|
||||
// @Success 200 {object} model.GeneralResponse{data=model.GetPriRecordsResp}
|
||||
// @Router /app/pri-chat-record [post]
|
||||
func GetPriRecords(ctx *svc.ServiceContext) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
req := &model.GetPriRecordsReq{}
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
userId, ok := c.Get(api.Address)
|
||||
if !ok {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.SignatureInvalid))
|
||||
return
|
||||
}
|
||||
req.FromId = userId.(string)
|
||||
|
||||
if req.Mid == "" {
|
||||
req.Mid = "999999999999999999"
|
||||
}
|
||||
|
||||
l := record.NewLogic(c.Request.Context(), ctx)
|
||||
data, err := l.GetPriRecord(req)
|
||||
c.Set(api.ReqResult, data)
|
||||
c.Set(api.ReqError, err)
|
||||
}
|
||||
}
|
||||
49
gateway/api/v1/internal/handler/record/revokehandler.go
Normal file
49
gateway/api/v1/internal/handler/record/revokehandler.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/logic/record"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/api"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
)
|
||||
|
||||
// RevokeHandler
|
||||
// @Summary 撤回消息
|
||||
// @Description
|
||||
// @Author dld@33.cn
|
||||
// @Tags record 消息模块
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param FZM-SIGNATURE header string true "MOCK"
|
||||
// @Param data body model.RevokeMsgReq true "body"
|
||||
// @Success 200 {object} model.GeneralResponse{}
|
||||
// @Router /app/record/revoke [post]
|
||||
func RevokeHandler(ctx *svc.ServiceContext) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
req := &model.RevokeMsgReq{}
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
var err error
|
||||
operator := c.MustGet(api.Address).(string)
|
||||
l := record.NewLogic(c.Request.Context(), ctx)
|
||||
switch req.Type {
|
||||
case model.Private:
|
||||
err = l.RevokePersonal(operator, req.Mid)
|
||||
case model.Group:
|
||||
err = l.RevokeGroup(operator, req.Mid)
|
||||
default:
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage("undefined type"))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
c.Set(api.ReqError, xerror.NewError(xerror.CodeInnerError).SetExtMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
c.Set(api.ReqResult, nil)
|
||||
c.Set(api.ReqError, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user