parent
d58bcd136a
commit
1607853393
@ -1 +1,15 @@
|
||||
package open_im_cms_api
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/cms_api"
|
||||
"Open_IM/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := cms_api.NewGinRouter()
|
||||
router.Use(utils.CorsHandler())
|
||||
router.Run(":" + "8000")
|
||||
}
|
||||
|
@ -1,80 +1,25 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"Open_IM/pkg/req_resp"
|
||||
|
||||
"Open_IM/test"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func MessagesStatistics(c *gin.Context) {
|
||||
var (
|
||||
req req_resp.StatisticsRequest
|
||||
//resp req_resp.MessageStatisticsResponse
|
||||
)
|
||||
if err := c.ShouldBindUri(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{})
|
||||
return
|
||||
}
|
||||
if _, err := test.RpcFake(); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
fakeData := test.GetUserStatisticsResponseFake()
|
||||
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
|
||||
|
||||
}
|
||||
|
||||
func UsersStatistics(c *gin.Context) {
|
||||
var (
|
||||
req req_resp.StatisticsRequest
|
||||
//resp req_resp.MessageStatisticsResponse
|
||||
)
|
||||
if err := c.ShouldBindUri(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{})
|
||||
return
|
||||
}
|
||||
if _, err := test.RpcFake(); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
fakeData := test.GetUserStatisticsResponseFake()
|
||||
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
|
||||
|
||||
}
|
||||
|
||||
func GroupsStatistics(c *gin.Context) {
|
||||
var (
|
||||
req req_resp.StatisticsRequest
|
||||
//resp req_resp.MessageStatisticsResponse
|
||||
)
|
||||
if err := c.ShouldBindUri(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{})
|
||||
return
|
||||
}
|
||||
if _, err := test.RpcFake(); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
fakeData := test.GetUserStatisticsResponseFake()
|
||||
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
|
||||
|
||||
}
|
||||
|
||||
func GetActiveUser(c *gin.Context) {
|
||||
if _, err := test.RpcFake(); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
fakeData := test.GetActiveUserResponseFake()
|
||||
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
|
||||
|
||||
}
|
||||
|
||||
func GetActiveGroup(c *gin.Context) {
|
||||
if _, err := test.RpcFake(); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
fakeData := test.GetActiveGroupResponseFake()
|
||||
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
|
||||
|
||||
}
|
||||
|
@ -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.BindJSON(&req); err != nil {
|
||||
if err := c.ShouldBindQuery(&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
|
||||
}
|
||||
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)
|
||||
respPb, err := client.GetUser(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
log.NewError("s", "GetUserInfo failed ", err.Error())
|
||||
openIMHttp.RespHttp200(c, err.(constant.ErrInfo), nil)
|
||||
return
|
||||
}
|
||||
//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)
|
||||
// resp.UserId = resp.UserId
|
||||
// resp.Nickname = resp.UserId
|
||||
// resp.ProfilePhoto = resp.ProfilePhoto
|
||||
// resp.UserResponse =
|
||||
utils.CopyStructFields(&resp, respPb)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func ResignUser(c *gin.Context) {
|
||||
|
||||
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(&reqPb, &req)
|
||||
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.OK, resp)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -1,7 +1,65 @@
|
||||
package cms_api_struct
|
||||
|
||||
type UserResponse struct {
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
Nickname string `json:"nick_name"`
|
||||
UserId string `json:"user_id"`
|
||||
CreateTime string `json:"create_time"`
|
||||
}
|
||||
|
||||
type GetUserRequest struct {
|
||||
UserId string `form:"user_id"`
|
||||
}
|
||||
|
||||
type GetUserResponse struct {
|
||||
UserResponse
|
||||
}
|
||||
|
||||
type GetUsersRequest struct {
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type GetUsersResponse struct {
|
||||
Users []*UserResponse `json:"users"`
|
||||
}
|
||||
|
||||
type ResignUserRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
type ResignUserResponse struct {
|
||||
}
|
||||
|
||||
type AlterUserRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
type AlterUserResponse struct {
|
||||
}
|
||||
|
||||
type AddUserRequest struct {
|
||||
}
|
||||
|
||||
type AddUserResponse struct {
|
||||
}
|
||||
|
||||
type BlockUserRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
type BlockUserResponse struct {
|
||||
}
|
||||
|
||||
type UnblockUserRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
}
|
||||
|
||||
type UnBlockUserResponse struct {
|
||||
}
|
||||
|
||||
type GetBlockUsersRequest struct {
|
||||
RequestPagination
|
||||
}
|
||||
|
||||
type GetBlockUsersResponse struct {
|
||||
}
|
||||
|
@ -1 +1,23 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type BaseResp struct {
|
||||
Code int32 `json:"code"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func RespHttp200(ctx *gin.Context, err constant.ErrInfo, data interface{}) {
|
||||
resp := BaseResp{
|
||||
Code: err.Code(),
|
||||
ErrMsg: err.Error(),
|
||||
Data: data,
|
||||
}
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
|
||||
all_proto=(
|
||||
auth/auth.proto
|
||||
friend/friend.proto
|
||||
group/group.proto
|
||||
# auth/auth.proto
|
||||
# friend/friend.proto
|
||||
# group/group.proto
|
||||
user/user.proto
|
||||
chat/chat.proto
|
||||
push/push.proto
|
||||
relay/relay.proto
|
||||
# chat/chat.proto
|
||||
# push/push.proto
|
||||
# relay/relay.proto
|
||||
sdk_ws/ws.proto
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue