mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-10 03:56:00 +08:00
cms
This commit is contained in:
+175
-35
@@ -1,76 +1,216 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
openIMHttp "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
rpc "Open_IM/pkg/proto/user"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
pb "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.RequestPagination
|
||||
resp cms_api_struct.GetUsersResponse
|
||||
reqPb rpc.GetUserInfoReq
|
||||
respPb *rpc.GetUserInfoResp
|
||||
req cms_api_struct.GetUserRequest
|
||||
resp cms_api_struct.GetUserResponse
|
||||
reqPb pb.GetUserReq
|
||||
respPb *pb.GetUserResp
|
||||
)
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), nil)
|
||||
return
|
||||
}
|
||||
// resp.UserId = resp.UserId
|
||||
// resp.Nickname = resp.UserId
|
||||
// resp.ProfilePhoto = resp.ProfilePhoto
|
||||
// resp.UserResponse =
|
||||
utils.CopyStructFields(&resp, respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
func GetUsers(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetUsersRequest
|
||||
resp cms_api_struct.GetUsersResponse
|
||||
reqPb pb.GetUsersReq
|
||||
respPb *pb.GetUsersResp
|
||||
)
|
||||
reqPb.Pagination = &commonPb.RequestPagination{}
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb.Pagination, &req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetUsers(context.Background(), &reqPb)
|
||||
for _, v := range respPb.User {
|
||||
resp.Users = append(resp.Users, &cms_api_struct.UserResponse{
|
||||
ProfilePhoto: v.ProfilePhoto,
|
||||
Nickname: v.Nickname,
|
||||
UserId: v.UserID,
|
||||
CreateTime: v.CreateTime,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
}
|
||||
fmt.Println(resp)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
|
||||
}
|
||||
|
||||
func ResignUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.ResignUserRequest
|
||||
resp cms_api_struct.ResignUserResponse
|
||||
reqPb pb.ResignUserReq
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(req, &req)
|
||||
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetUserInfo(context.Background(), &reqPb)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
_, err := client.ResignUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
openIMHttp.RespHttp200(c, constant.ErrDB, resp)
|
||||
}
|
||||
//for _, v := range RpcResp.UserInfoList {
|
||||
// publicUserInfoList = append(publicUserInfoList,
|
||||
// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, AppMangerLevel: v.AppMangerLevel})
|
||||
//}
|
||||
|
||||
//resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||
//resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||
//log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func ResignUser(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
func AlterUser(c *gin.Context) {
|
||||
|
||||
var (
|
||||
req cms_api_struct.AlterUserRequest
|
||||
resp cms_api_struct.AlterUserResponse
|
||||
reqPb pb.AlterUserReq
|
||||
respPb *pb.AlterUserResp
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.AlterUser(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func AddUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.AddUserRequest
|
||||
resp cms_api_struct.AddUserResponse
|
||||
reqPb pb.AddUserReq
|
||||
respPb *pb.AddUserResp
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.AddUser(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func BlockUser(c *gin.Context) {
|
||||
|
||||
var (
|
||||
req cms_api_struct.BlockUserRequest
|
||||
resp cms_api_struct.BlockUserResponse
|
||||
reqPb pb.BlockUserReq
|
||||
respPb *pb.BlockUserResp
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.BlockUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func UnblockUser(c *gin.Context) {
|
||||
|
||||
var (
|
||||
req cms_api_struct.UnblockUserRequest
|
||||
resp cms_api_struct.UnBlockUserResponse
|
||||
reqPb pb.UnBlockUserReq
|
||||
respPb *pb.UnBlockUserResp
|
||||
)
|
||||
utils.CopyStructFields(&reqPb, req)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.UnBlockUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func GetBlockUsers(c *gin.Context) {
|
||||
|
||||
var (
|
||||
req cms_api_struct.GetBlockUsersRequest
|
||||
resp cms_api_struct.GetOrganizationsResponse
|
||||
reqPb pb.GetBlockUsersReq
|
||||
respPb *pb.GetBlockUsersResp
|
||||
)
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetBlockUsers(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user