Files
open-im-server/internal/cms_api/message_cms/message.go
T

60 lines
2.1 KiB
Go
Raw Normal View History

2022-02-09 16:22:58 +08:00
package messageCMS
2022-01-21 18:39:57 +08:00
import (
2022-02-09 00:45:23 +08:00
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
2022-08-26 17:51:01 +08:00
pbAdminCMS "Open_IM/pkg/proto/admin_cms"
2022-02-09 16:22:58 +08:00
pbCommon "Open_IM/pkg/proto/sdk_ws"
2022-02-09 00:45:23 +08:00
"Open_IM/pkg/utils"
"context"
2022-06-16 14:09:28 +08:00
"net/http"
2022-02-09 00:45:23 +08:00
"strings"
2022-01-21 18:39:57 +08:00
2022-02-07 08:44:21 +08:00
"github.com/gin-gonic/gin"
)
2022-01-24 01:40:49 +08:00
2022-02-09 00:45:23 +08:00
func GetChatLogs(c *gin.Context) {
var (
2022-08-26 17:51:01 +08:00
req cms_api_struct.GetChatLogsReq
resp cms_api_struct.GetChatLogsResp
reqPb pbAdminCMS.GetChatLogsReq
2022-02-09 00:45:23 +08:00
)
2022-08-30 01:38:23 +08:00
if err := c.Bind(&req); err != nil {
2022-02-09 00:45:23 +08:00
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
2022-08-30 01:38:23 +08:00
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
2022-02-09 00:45:23 +08:00
return
}
2022-02-09 16:22:58 +08:00
reqPb.Pagination = &pbCommon.RequestPagination{
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
2022-02-09 00:45:23 +08:00
utils.CopyStructFields(&reqPb, &req)
2022-06-16 14:09:28 +08:00
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "req: ", req)
2022-08-31 00:43:06 +08:00
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, reqPb.OperationID)
2022-06-16 14:09:28 +08:00
if etcdConn == nil {
2022-08-17 12:12:54 +08:00
errMsg := reqPb.OperationID + "getcdv3.GetDefaultConn == nil"
2022-06-16 14:09:28 +08:00
log.NewError(reqPb.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
2022-08-26 17:51:01 +08:00
client := pbAdminCMS.NewAdminCMSClient(etcdConn)
2022-02-09 00:45:23 +08:00
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
2022-08-31 00:43:06 +08:00
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
2022-02-09 00:45:23 +08:00
return
}
2022-08-26 17:51:01 +08:00
for _, v := range respPb.ChatLogs {
2022-09-02 02:01:42 +08:00
chatLog := cms_api_struct.ChatLog{}
2022-08-26 17:51:01 +08:00
utils.CopyStructFields(&chatLog, v)
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
2022-02-17 19:35:17 +08:00
}
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ChatLogsNum = int(respPb.ChatLogsNum)
2022-06-16 14:09:28 +08:00
log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "resp", resp)
2022-08-30 01:38:23 +08:00
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
2022-02-09 00:45:23 +08:00
}