You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/cmsapi/message_cms/message.go

60 lines
2.1 KiB

3 years ago
package messageCMS
3 years ago
import (
3 years ago
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/getcdv3"
2 years ago
pbAdminCMS "Open_IM/pkg/proto/admin_cms"
3 years ago
pbCommon "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
"context"
"net/http"
3 years ago
"strings"
3 years ago
3 years ago
"github.com/gin-gonic/gin"
)
3 years ago
3 years ago
func GetChatLogs(c *gin.Context) {
var (
2 years ago
req cms_struct.GetChatLogsReq
resp cms_struct.GetChatLogsResp
2 years ago
reqPb pbAdminCMS.GetChatLogsReq
3 years ago
)
2 years ago
if err := c.Bind(&req); err != nil {
3 years ago
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
2 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
3 years ago
return
}
3 years ago
reqPb.Pagination = &pbCommon.RequestPagination{
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
3 years ago
utils.CopyStructFields(&reqPb, &req)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
2 years ago
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
if etcdConn == nil {
2 years ago
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
2 years ago
client := pbAdminCMS.NewAdminCMSClient(etcdConn)
3 years ago
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
2 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
3 years ago
return
}
2 years ago
for _, v := range respPb.ChatLogs {
2 years ago
chatLog := cms_struct.ChatLog{}
2 years ago
utils.CopyStructFields(&chatLog, v)
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
3 years ago
}
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ChatLogsNum = int(respPb.ChatLogsNum)
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp", resp)
2 years ago
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
3 years ago
}