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/api/group/get_group_applicationList.go

114 lines
3.8 KiB

3 years ago
package group
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"Open_IM/pkg/proto/group"
3 years ago
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
type paramsGroupApplicationList struct {
OperationID string `json:"operationID" binding:"required"`
}
func newUserRegisterReq(params *paramsGroupApplicationList) *group.GetGroupApplicationListReq {
pbData := group.GetGroupApplicationListReq{
OperationID: params.OperationID,
}
return &pbData
}
type paramsGroupApplicationListRet struct {
ID string `json:"id"`
3 years ago
GroupID string `json:"groupID"`
FromUserID string `json:"fromUserID"`
ToUserID string `json:"toUserID"`
Flag int32 `json:"flag"`
RequestMsg string `json:"reqMsg"`
3 years ago
HandledMsg string `json:"handledMsg"`
AddTime int64 `json:"createTime"`
FromUserNickname string `json:"fromUserNickName"`
ToUserNickname string `json:"toUserNickName"`
FromUserFaceUrl string `json:"fromUserFaceURL"`
ToUserFaceUrl string `json:"toUserFaceURL"`
HandledUser string `json:"handledUser"`
3 years ago
Type int32 `json:"type"`
HandleStatus int32 `json:"handleStatus"`
HandleResult int32 `json:"handleResult"`
}
func GetGroupApplicationList(c *gin.Context) {
log.Info("", "", "api GetGroupApplicationList init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := group.NewGroupClient(etcdConn)
//defer etcdConn.Close()
3 years ago
params := paramsGroupApplicationList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
pbData := newUserRegisterReq(&params)
token := c.Request.Header.Get("token")
if claims, err := token_verify.ParseToken(token); err != nil {
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
return
} else {
pbData.UID = claims.UID
}
log.Info("", "", "api GetGroupApplicationList is server, [data: %s]", pbData.String())
reply, err := client.GetGroupApplicationList(context.Background(), pbData)
if err != nil {
log.Error("", "", "api GetGroupApplicationList call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
log.Info("", "", "api GetGroupApplicationList call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
unProcessCount := 0
userReq := make([]paramsGroupApplicationListRet, 0)
if reply != nil && reply.Data != nil && reply.Data.User != nil {
for i := 0; i < len(reply.Data.User); i++ {
req := paramsGroupApplicationListRet{}
req.ID = reply.Data.User[i].ID
req.GroupID = reply.Data.User[i].GroupID
req.FromUserID = reply.Data.User[i].FromUserID
req.ToUserID = reply.Data.User[i].ToUserID
req.Flag = reply.Data.User[i].Flag
req.RequestMsg = reply.Data.User[i].RequestMsg
req.HandledMsg = reply.Data.User[i].HandledMsg
req.AddTime = reply.Data.User[i].AddTime
req.FromUserNickname = reply.Data.User[i].FromUserNickname
req.ToUserNickname = reply.Data.User[i].ToUserNickname
req.FromUserFaceUrl = reply.Data.User[i].FromUserFaceUrl
req.ToUserFaceUrl = reply.Data.User[i].ToUserFaceUrl
req.HandledUser = reply.Data.User[i].HandledUser
req.Type = reply.Data.User[i].Type
req.HandleStatus = reply.Data.User[i].HandleStatus
req.HandleResult = reply.Data.User[i].HandleResult
userReq = append(userReq, req)
if req.Flag == 0 {
unProcessCount++
}
}
3 years ago
}
c.JSON(http.StatusOK, gin.H{
"errCode": reply.ErrCode,
"errMsg": reply.ErrMsg,
"data": gin.H{
"count": unProcessCount,
3 years ago
"user": userReq,
},
})
}