mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-16 23:09:01 +08:00
cms
This commit is contained in:
@@ -1,20 +1,99 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
openIMHttp "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"strings"
|
||||
"context"
|
||||
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func SearchGroups(c *gin.Context) {
|
||||
func GetGroups(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupsRequest
|
||||
resp cms_api_struct.GetGroupsResponse
|
||||
reqPb pbGroup.GetGroupsReq
|
||||
)
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.GetGroups(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
|
||||
}
|
||||
|
||||
func GetGroup(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupRequest
|
||||
resp cms_api_struct.GetGroupResponse
|
||||
reqPb pbGroup.GetGroupReq
|
||||
)
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
log.NewError("0", "ShouldBindQuery 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.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.GetGroup(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func CreateGroup(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.CreateGroupRequest
|
||||
resp cms_api_struct.CreateGroupResponse
|
||||
reqPb pbGroup.CreateGroupReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
reqPb.GroupInfo.GroupName = req.GroupName
|
||||
reqPb.
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
respPb, err := client.CreateGroup(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
if err != nil {
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func SearchGroupsMember(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func CreateGroup(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func AddUsers(c *gin.Context) {
|
||||
|
||||
|
||||
@@ -57,11 +57,12 @@ func NewGinRouter() *gin.Engine {
|
||||
}
|
||||
groupRouterGroup := router.Group("/groups")
|
||||
{
|
||||
groupRouterGroup.GET("/search_groups", group.SearchGroups)
|
||||
groupRouterGroup.GET("/get_groups", group.GetGroups)
|
||||
groupRouterGroup.GET("/get_group", group.GetGroup)
|
||||
groupRouterGroup.GET("/search_groups_member", group.SearchGroupsMember)
|
||||
groupRouterGroup.POST("/create_group", group.CreateGroup)
|
||||
groupRouterGroup.GET("/inquire_group", group.InquireGroup)
|
||||
groupRouterGroup.GET("/inquireMember_by_group", group.InquireMember)
|
||||
groupRouterGroup.GET("/inquire_member_by_group", group.InquireMember)
|
||||
groupRouterGroup.POST("/add_members", group.AddMembers)
|
||||
groupRouterGroup.POST("/set_master", group.SetMaster)
|
||||
groupRouterGroup.POST("/block_user", group.BlockUser)
|
||||
@@ -79,7 +80,7 @@ func NewGinRouter() *gin.Engine {
|
||||
userRouterGroup.POST("/add_user", user.AddUser)
|
||||
userRouterGroup.POST("/unblock_user", user.UnblockUser)
|
||||
userRouterGroup.POST("/block_user", user.BlockUser)
|
||||
userRouterGroup.GET("/block_users", user.GetBlockUsers)
|
||||
userRouterGroup.GET("/get_block_users", user.GetBlockUsers)
|
||||
}
|
||||
return baseRouter
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -23,27 +24,26 @@ func GetUser(c *gin.Context) {
|
||||
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())
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, req)
|
||||
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)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
// resp.UserId = resp.UserId
|
||||
// resp.Nickname = resp.UserId
|
||||
// resp.ProfilePhoto = resp.ProfilePhoto
|
||||
// resp.UserResponse =
|
||||
utils.CopyStructFields(&resp, respPb)
|
||||
if respPb.User.UserId == "" {
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&resp, respPb.User)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -52,11 +52,10 @@ func GetUsers(c *gin.Context) {
|
||||
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())
|
||||
log.NewError("0", "ShouldBindQuery failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
@@ -64,18 +63,14 @@ func GetUsers(c *gin.Context) {
|
||||
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)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
return
|
||||
}
|
||||
fmt.Println(resp)
|
||||
utils.CopyStructFields(&resp.Users, respPb.User)
|
||||
resp.UserNum = int(respPb.UserNum)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
|
||||
}
|
||||
@@ -92,11 +87,12 @@ func ResignUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
fmt.Println(reqPb.UserId)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pb.NewUserClient(etcdConn)
|
||||
_, err := client.ResignUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, constant.ErrDB, resp)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
@@ -106,7 +102,7 @@ func AlterUser(c *gin.Context) {
|
||||
req cms_api_struct.AlterUserRequest
|
||||
resp cms_api_struct.AlterUserResponse
|
||||
reqPb pb.AlterUserReq
|
||||
respPb *pb.AlterUserResp
|
||||
_ *pb.AlterUserResp
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
@@ -116,10 +112,9 @@ func AlterUser(c *gin.Context) {
|
||||
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)
|
||||
_, err := client.AlterUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
@@ -127,23 +122,23 @@ func AlterUser(c *gin.Context) {
|
||||
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 {
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
|
||||
return
|
||||
}
|
||||
fmt.Println(time.Now().String())
|
||||
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.AddUser(context.Background(), &reqPb)
|
||||
fmt.Println(respPb)
|
||||
_, err := client.AddUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, nil)
|
||||
return
|
||||
}
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
openIMHttp.RespHttp200(c, constant.OK, nil)
|
||||
}
|
||||
|
||||
func BlockUser(c *gin.Context) {
|
||||
@@ -151,21 +146,23 @@ func BlockUser(c *gin.Context) {
|
||||
req cms_api_struct.BlockUserRequest
|
||||
resp cms_api_struct.BlockUserResponse
|
||||
reqPb pb.BlockUserReq
|
||||
respPb *pb.BlockUserResp
|
||||
)
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
fmt.Println(err)
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(&reqPb, req)
|
||||
utils.CopyStructFields(&reqPb, &req)
|
||||
fmt.Println(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)
|
||||
fmt.Println(reqPb)
|
||||
_, err := client.BlockUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
return
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -174,43 +171,48 @@ func UnblockUser(c *gin.Context) {
|
||||
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
|
||||
}
|
||||
fmt.Println(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.UnBlockUser(context.Background(), &reqPb)
|
||||
_, err := client.UnBlockUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
return
|
||||
}
|
||||
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
|
||||
resp cms_api_struct.GetBlockUsersResponse
|
||||
reqPb pb.GetBlockUsersReq
|
||||
respPb *pb.GetBlockUsersResp
|
||||
)
|
||||
reqPb.Pagination = &commonPb.RequestPagination{}
|
||||
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)
|
||||
utils.CopyStructFields(&reqPb.Pagination, &req)
|
||||
log.NewInfo("0", "blockUsers", 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.GetBlockUsers(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), resp)
|
||||
openIMHttp.RespHttp200(c, constant.ErrServer, resp)
|
||||
return
|
||||
}
|
||||
fmt.Println(respPb)
|
||||
utils.CopyStructFields(&resp.BlockUsers, respPb.User)
|
||||
resp.BlockUserNum = int(respPb.BlockUserNum)
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -121,12 +121,12 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
||||
// case constant.GroupChatType:
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
// client := pbGroup.NewGroupClient(etcdConn)
|
||||
// req := &pbGroup.GetGroupAllMemberReq{
|
||||
// req := &pbGroup.Req{
|
||||
// GroupID: m.RecvID,
|
||||
// Token: config.Config.Secret,
|
||||
// OperationID: m.OperationID,
|
||||
// }
|
||||
// reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
// reply, err := client.(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.Error(m.Token, m.OperationID, "rpc getGroupInfo failed, err = %s", err.Error())
|
||||
// return
|
||||
|
||||
@@ -638,3 +638,31 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroup ", req.String())
|
||||
group, err := imdb.GetGroupByName(req.GroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbGroup.GetGroupResp{
|
||||
GroupInfo: &open_im_sdk.GroupInfo{
|
||||
},
|
||||
}
|
||||
utils.CopyStructFields(resp.GroupInfo, group)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroups ", req.String())
|
||||
groups, err := imdb.GetGroups(int(req.Pagination.PageNumber), int(req.Pagination.ShowNumber))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbGroup.GetGroupsResp{
|
||||
GroupInfo: []*open_im_sdk.GroupInfo,
|
||||
}
|
||||
utils.CopyStructFields(resp.GroupInfo, groups)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
+85
-24
@@ -14,11 +14,11 @@ import (
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
@@ -214,7 +214,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
var user db.User
|
||||
var user db.Users
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.Birth != 0 {
|
||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||
@@ -243,61 +243,122 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
}
|
||||
|
||||
func (s *userServer) GetUser(ctx context.Context, req *pbUser.GetUserReq) (*pbUser.GetUserResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
|
||||
resp := &pbUser.GetUserResp{}
|
||||
log.NewInfo(req.OperationID, "GetUser args ", req.String())
|
||||
resp := &pbUser.GetUserResp{User:&pbUser.User{}}
|
||||
user, err := imdb.GetUserByUserID(req.UserId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectAllUserID false ", err.Error())
|
||||
return resp, nil
|
||||
}
|
||||
resp.User.CreateTime = user.CreateTime.String()
|
||||
resp.User.ProfilePhoto = ""
|
||||
resp.User.Nickname = user.Nickname
|
||||
resp.User.UserID = user.UserID
|
||||
resp.User = &pbUser.User{
|
||||
ProfilePhoto: user.FaceURL,
|
||||
Nickname: user.Nickname,
|
||||
UserId: user.UserID,
|
||||
CreateTime: user.CreateTime.String(),
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUsers args ", req.String())
|
||||
resp := &pbUser.GetUsersResp{}
|
||||
resp := &pbUser.GetUsersResp{User:[]*pbUser.User{}}
|
||||
users, err := imdb.GetUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectAllUserID false ", err.Error())
|
||||
return resp, nil
|
||||
}
|
||||
for _, v := range users {
|
||||
resp.User = append(resp.User, &pbUser.User{
|
||||
ProfilePhoto: "",
|
||||
UserID: v.UserID,
|
||||
CreateTime: v.CreateTime.String(),
|
||||
Nickname: v.Nickname,
|
||||
})
|
||||
usersNum, err := imdb.GetUsersNumCount()
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
}
|
||||
resp.UserNum = int32(usersNum)
|
||||
for _, v := range users {
|
||||
isBlock, err := imdb.UserIsBlock(v.UserID)
|
||||
if err == nil {
|
||||
user := &pbUser.User{
|
||||
ProfilePhoto: v.FaceURL,
|
||||
UserId: v.UserID,
|
||||
CreateTime: v.CreateTime.String(),
|
||||
Nickname: v.Nickname,
|
||||
IsBlock: isBlock,
|
||||
}
|
||||
resp.User = append(resp.User, user)
|
||||
}
|
||||
}
|
||||
|
||||
resp.Pagination = &sdkws.ResponsePagination{}
|
||||
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
|
||||
resp.Pagination.CurrentPage = req.Pagination.PageNumber
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) ResignUser(ctx context.Context, req *pbUser.ResignUserReq) (*pbUser.ResignUserResp, error) {
|
||||
log.NewInfo(req.OperationID, "ResignUser args ", req.String())
|
||||
|
||||
return &pbUser.ResignUserResp{}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (*pbUser.AlterUserResp, error) {
|
||||
log.NewInfo(req.OperationID, "AlterUser args ", req.String())
|
||||
return &pbUser.AlterUserResp{}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) {
|
||||
return &pbUser.AddUserResp{}, nil
|
||||
log.NewInfo(req.OperationID, "AddUser args ", req.String())
|
||||
resp := &pbUser.AddUserResp{}
|
||||
err := imdb.AddUser(req.UserId, req.PhoneNumber, req.Name)
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (*pbUser.BlockUserResp, error) {
|
||||
return &pbUser.BlockUserResp{}, nil
|
||||
log.NewInfo(req.OperationID, "BlockUser args ", req.String())
|
||||
fmt.Println("BlockUser args ", req.String())
|
||||
resp := &pbUser.BlockUserResp{}
|
||||
err := imdb.BlockUser(req.UserId, req.EndDisableTime)
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq) (*pbUser.UnBlockUserResp, error) {
|
||||
return &pbUser.UnBlockUserResp{}, nil
|
||||
log.NewInfo(req.OperationID, "UnBlockUser args ", req.String())
|
||||
fmt.Println(req.UserId)
|
||||
resp := &pbUser.UnBlockUserResp{}
|
||||
err := imdb.UnBlockUser(req.UserId)
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUsersReq) (*pbUser.GetBlockUsersResp, error) {
|
||||
return &pbUser.GetBlockUsersResp{}, nil
|
||||
log.NewInfo(req.OperationID, "GetBlockUsers args ", req.String())
|
||||
resp := &pbUser.GetBlockUsersResp{}
|
||||
blockUserIds, err := imdb.GetBlockUsersID(req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
usersNum, err := imdb.GetBlockUsersNumCount()
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
resp.BlockUserNum = int32(usersNum)
|
||||
blockUsers, err := imdb.GetBlockUsers(blockUserIds)
|
||||
if err != nil {
|
||||
return resp, constant.ErrDB
|
||||
}
|
||||
for _, v := range blockUsers {
|
||||
resp.User = append(resp.User, &pbUser.User{
|
||||
ProfilePhoto: v.FaceURL,
|
||||
Nickname: v.Nickname,
|
||||
UserId: v.UserID,
|
||||
CreateTime: v.CreateTime.String(),
|
||||
IsBlock: true,
|
||||
})
|
||||
}
|
||||
resp.Pagination = &sdkws.ResponsePagination{}
|
||||
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
|
||||
resp.Pagination.CurrentPage = req.Pagination.PageNumber
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user