pull/131/head
wangchuxiao 3 years ago
parent 1944b24fba
commit d58bcd136a

@ -0,0 +1 @@
package open_im_cms_api

@ -0,0 +1,24 @@
package admin
import (
"net/http"
"github.com/gin-gonic/gin"
)
// register
func UserLogin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
}
func UserRegister(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
}
func GetUserSettings(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
}
func AlterUserSettings(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "someJSON", "status": 200})
}

@ -0,0 +1,67 @@
package group
import (
_ "Open_IM_CMS/pkg/req_resp"
"Open_IM_CMS/test"
"net/http"
"github.com/gin-gonic/gin"
)
func SearchGroups(c *gin.Context) {
fake := test.GetSearchGroupsResponseFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fake})
}
func SearchGroupsMember(c *gin.Context) {
fake := test.GetSearchMemberResponseFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fake})
}
func CreateGroup(c *gin.Context) {
}
func AddUsers(c *gin.Context) {
}
func InquireMember(c *gin.Context) {
}
func InquireGroup(c *gin.Context) {
}
func AddGroupMember(c *gin.Context) {
}
func AddMembers(c *gin.Context) {
}
func SetMaster(c *gin.Context) {
}
func BlockUser(c *gin.Context) {
}
func RemoveUser(c *gin.Context) {
}
func BanPrivateChat(c *gin.Context) {
}
func Withdraw(c *gin.Context) {
}
func SearchMessage(g *gin.Context) {
}

@ -0,0 +1,31 @@
package message
import (
"net/http"
"Open_IM_CMS/test"
"github.com/gin-gonic/gin"
)
func Broadcast(c *gin.Context) {
}
func SearchMessageByUser(c *gin.Context) {
fake := test.GetSearchUserMsgFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fake})
}
func SearchMessageByGroup(c *gin.Context) {
fake := test.GetSearchGroupMsgFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fake})
}
func MassSendMassage(c *gin.Context) {
}
func Withdraw(c *gin.Context) {
}

@ -0,0 +1,23 @@
package middleware
import (
"github.com/gin-gonic/gin"
"net/http"
)
func CorsHandler() gin.HandlerFunc {
return func(context *gin.Context) {
context.Writer.Header().Set("Access-Control-Allow-Origin", "*")
context.Header("Access-Control-Allow-Methods", "*")
context.Header("Access-Control-Allow-Headers", "*")
context.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析
context.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒
context.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
context.Header("content-type", "application/json") // 设置返回格式是json
//Release all option pre-requests
if context.Request.Method == http.MethodOptions {
context.JSON(http.StatusOK, "Options Request!")
}
context.Next()
}
}

@ -0,0 +1,11 @@
package middleware
import (
"github.com/gin-gonic/gin"
)
func JWTAuth() gin.HandlerFunc {
return func(c *gin.Context) {
}
}

@ -0,0 +1,82 @@
package organization
import (
"Open_IM_CMS/pkg/common/config"
"Open_IM_CMS/pkg/errno"
"Open_IM_CMS/pkg/etcdv3"
commonProto "Open_IM_CMS/pkg/proto/common"
proto "Open_IM_CMS/pkg/proto/organization"
"Open_IM_CMS/pkg/req_resp"
"Open_IM_CMS/test"
"context"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func GetStaffs(c *gin.Context) {
var (
req req_resp.GetStaffsResponse
resp req_resp.GetStaffsResponse
reqPb commonProto.Pagination
respPb *proto.GetStaffsResp
)
fmt.Println(resp, req)
fakeData := test.GetStaffsResponseFake()
etcdConn := etcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCMSApiOrganizationName)
client := proto.NewOrganizationClient(etcdConn)
fmt.Println(client, reqPb)
respPb, err := client.GetStaffs(context.Background(), &reqPb)
fmt.Println(respPb, err)
fmt.Println(etcdConn)
req_resp.RespHttp200(c, errno.RespOK, fakeData)
}
func GetOrganizations(c *gin.Context) {
var (
req req_resp.GetOrganizationsResponse
resp req_resp.GetStaffsResponse
)
fmt.Println(resp, req)
fakeData := test.GetOrganizationsResponseFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
}
func GetSquads(c *gin.Context) {
fakeData := test.GetSquadResponseFake()
c.JSON(http.StatusOK, gin.H{"code": "0", "data": fakeData})
}
func AlterStaff(c *gin.Context) {
}
func AddOrganization(c *gin.Context) {
}
func InquireOrganization(g *gin.Context) {
}
func AlterOrganization(c *gin.Context) {
}
func DeleteOrganization(g *gin.Context) {
}
func GetOrganizationSquads(c *gin.Context) {
}
func AlterStaffsInfo(c *gin.Context) {
}
func AddChildOrganization(c *gin.Context) {
}

@ -0,0 +1,85 @@
package cms_api
import (
"Open_IM/internal/cms_api/admin"
"Open_IM/internal/cms_api/group"
"Open_IM/internal/cms_api/message"
"Open_IM/internal/cms_api/middleware"
"Open_IM/internal/cms_api/organization"
"Open_IM/internal/cms_api/statistics"
"Open_IM/internal/cms_api/user"
"github.com/gin-gonic/gin"
)
func NewGinRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
baseRouter := gin.Default()
router := baseRouter.Group("/api")
router.Use(middleware.JWTAuth())
router.Use(middleware.CorsHandler())
adminRouterGroup := router.Group("/admin")
{
adminRouterGroup.POST("/register", admin.UserRegister)
adminRouterGroup.POST("/login", admin.UserLogin)
adminRouterGroup.GET("/get_user_settings", admin.GetUserSettings)
adminRouterGroup.POST("/alter_user_settings", admin.AlterUserSettings)
}
statisticsRouterGroup := router.Group("/statistics")
{
statisticsRouterGroup.GET("/get_messages_statistics", statistics.MessagesStatistics)
statisticsRouterGroup.GET("/get_users_statistics", statistics.UsersStatistics)
statisticsRouterGroup.GET("/get_groups_statistics", statistics.GroupsStatistics)
statisticsRouterGroup.GET("/get_active_user", statistics.GetActiveUser)
statisticsRouterGroup.GET("/get_active_group", statistics.GetActiveGroup)
}
organizationRouterGroup := router.Group("/organization")
{
organizationRouterGroup.GET("/get_staffs", organization.GetStaffs)
organizationRouterGroup.GET("/get_organizations", organization.GetOrganizations)
organizationRouterGroup.GET("/get_squad", organization.GetSquads)
organizationRouterGroup.POST("/add_organization", organization.AddOrganization)
organizationRouterGroup.POST("/alter_staff", organization.AlterStaff)
organizationRouterGroup.GET("/inquire_organization", organization.InquireOrganization)
organizationRouterGroup.POST("/alter_organization", organization.AlterOrganization)
organizationRouterGroup.POST("/delete_organization", organization.DeleteOrganization)
organizationRouterGroup.POST("/get_organization_squad", organization.GetOrganizationSquads)
organizationRouterGroup.PATCH("/alter_corps_info", organization.AlterStaffsInfo)
organizationRouterGroup.POST("/add_child_org", organization.AddChildOrganization)
}
messageRouterGroup := router.Group("/message")
{
messageRouterGroup.POST("/broadcast", message.Broadcast)
messageRouterGroup.GET("/search_message_by_user", message.SearchMessageByUser)
messageRouterGroup.POST("/message_mass_send", message.MassSendMassage)
messageRouterGroup.GET("/search_message_by_group", message.SearchMessageByGroup)
messageRouterGroup.POST("/withdraw_message", message.Withdraw)
}
groupRouterGroup := router.Group("/groups")
{
groupRouterGroup.GET("/search_groups", group.SearchGroups)
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.POST("/add_members", group.AddMembers)
groupRouterGroup.POST("/set_master", group.SetMaster)
groupRouterGroup.POST("/block_user", group.BlockUser)
groupRouterGroup.POST("/remove_user", group.RemoveUser)
groupRouterGroup.POST("/ban_private_chat", group.BanPrivateChat)
groupRouterGroup.POST("/withdraw_message", group.Withdraw)
groupRouterGroup.POST("/search_group_message", group.SearchMessage)
}
userRouterGroup := router.Group("/users")
{
userRouterGroup.POST("/resign", user.ResignUser)
userRouterGroup.GET("/get_user", user.GetUser)
userRouterGroup.POST("/alter_user", user.AlterUser)
userRouterGroup.GET("/get_users", user.GetUsers)
userRouterGroup.POST("/add_user", user.AddUser)
userRouterGroup.POST("/unblock_user", user.UnblockUser)
userRouterGroup.POST("/block_user", user.BlockUser)
userRouterGroup.GET("/block_users", user.GetBlockUsers)
}
return baseRouter
}

@ -0,0 +1,80 @@
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})
}

@ -0,0 +1,76 @@
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/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
rpc "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
func GetUser(c *gin.Context) {
var (
req cms_api_struct.RequestPagination
resp cms_api_struct.GetUsersResponse
reqPb rpc.GetUserInfoReq
respPb *rpc.GetUserInfoResp
)
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()})
return
}
utils.CopyStructFields(req, &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)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
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)
}
func ResignUser(c *gin.Context) {
}
func AlterUser(c *gin.Context) {
}
func AddUser(c *gin.Context) {
}
func BlockUser(c *gin.Context) {
}
func UnblockUser(c *gin.Context) {
}
func GetBlockUsers(c *gin.Context) {
}

@ -0,0 +1 @@
package cms_api_struct

@ -0,0 +1,10 @@
package cms_api_struct
type RequestPagination struct {
PageNumber int `json:"page_number"`
ShowNumber int `json:"show_number"`
}

@ -0,0 +1,20 @@
package cms_api_struct
type SearchGroupsResponse struct {
GroupList []struct {
GroupNickName string `json:"group_nick_name"`
GroupID int `json:"group_id"`
MasterName string `json:"master_name"`
MasterId int `json:"master_id"`
CreatTime string `json:"creat_time"`
} `json:"group_list"`
}
type SearchGroupMemberResponse struct {
GroupMemberList []struct {
MemberPosition int `json:"member_position"`
MemberNickName string `json:"member_nick_name"`
MemberId int `json:"member_id"`
JoinTime string `json:"join_time"`
} `json:"group_member_list"`
}

@ -0,0 +1,27 @@
package cms_api_struct
type SearchMessageByUserResponse struct {
MessageList []struct {
ChatType int `json:"chat_type"`
MessageType int `json:"message_type"`
SenderNickName string `json:"sender_nick_name"`
SenderId int `json:"sender_id"`
ReceiverNickName string `json:"receiver_nick_name"`
ReceiverID int `json:"receiver_id"`
SearchContent string `json:"search_content"`
WholeContent string `json:"whole_content"`
Date string `json:"date"`
} `json:"massage_list"`
}
type SearchMessageByGroupResponse struct {
MessageList []struct {
ChatType int `json:"chat_type"`
MessageType int `json:"message_type"`
SenderNickName string `json:"sender_nick_name"`
SenderId int `json:"sender_id"`
SearchContent string `json:"search_content"`
WholeContent string `json:"whole_content"`
Date string `json:"date"`
} `json:"massage_list"`
}

@ -0,0 +1,25 @@
package cms_api_struct
type GetStaffsResponse struct {
StaffsList []struct {
ProfilePhoto string `json:"profile_photo"`
NickName string `json:"nick_name"`
StaffId int `json:"staff_id"`
Position string `json:"position"`
EntryTime string `json:"entry_time"`
} `json:"staffs_list"`
}
type GetOrganizationsResponse struct {
OrganizationList []struct {
OrganizationId int `json:"organization_id"`
OrganizationName string `json:"organization_name"`
} `json:"organization_list"`
}
type SquadResponse struct {
SquadList []struct {
SquadId int `json:"squad_id"`
SquadName string `json:"squad_name"`
} `json:"squad_list"`
}

@ -0,0 +1,69 @@
package cms_api_struct
type StatisticsRequest struct {
From string `json:"from"`
To string `json:"to"`
}
// 单聊
type MessageStatisticsResponse struct {
PrivateMessageNum int `json:"private_message_num"`
GroupMessageNum int `json:"group_message_num"`
PrivateMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"message_num"`
} `json:"private_message_num_list"`
GroupMessageNumList []struct {
Date string `json:"date"`
MessageNum int `json:"message_num"`
} `json:"group_message_num_list"`
}
// 用户统计
type UserStatisticsResponse struct {
IncreaseUserNum int `json:"increase_user_num"`
ActiveUserNum int `json:"active_user_num"`
TotalUserNum int `json:"total_user_num"`
IncreaseUserNumList []struct {
Date string `json:"date"`
IncreaseUserNum int `json:"increase_user_num"`
} `json:"increase_user_num_list"`
ActiveUserNumList []struct {
Date string `json:"date"`
ActiveUserNum int `json:"active_user_num"`
} `json:"active_user_num_list"`
TotalUserNumList []struct {
Date string `json:"date"`
TotalUserNum string `json:"total_user_num"`
} `json:"total_user_num_list"`
}
// 群聊统计
type GroupMessageStatisticsResponse struct {
IncreaseGroupNum int `json:"increase_group_num"`
TotalGroupNum int `json:"total_group_num"`
IncreaseGroupNumList []struct {
Date string `json:"date"`
IncreaseGroupNum int `json:"increase_group_num"`
} `json:"increase_group_num_list"`
TotalGroupNumList []struct {
Date string `json:"date"`
TotalGroupNum string `json:"total_group_num"`
} `json:"total_group_num_list"`
}
type ActiveUserStatisticsResponse struct {
ActiveUserList []struct {
NickName string `json:"nick_name"`
Id int `json:"id"`
MessageNum int `json:"message_num"`
} `json:"active_user_list"`
}
type ActiveGroupStatisticsResponse struct {
ActiveGroupList []struct {
GroupNickName string `json:"group_nick_name"`
GroupId int `json:"group_id"`
MessageNum int `json:"message_num"`
} `json:"active_group_list"`
}

@ -0,0 +1,7 @@
package cms_api_struct
type GetUsersResponse struct {
}

@ -106,6 +106,53 @@ message GetAllConversationMsgOptResp{
repeated OptResult conversationOptResultList = 3;
}
message ResignUserReq{
string UserId = 1;
string OperationID = 2;
}
message ResignUserResp{
CommonResp commonResp = 1;
}
message GetUserReq{
string UserId = 1;
string OperationID = 2;
}
message User{
}
message GetUserResp{
User user = 1
}
message AlterUserReq{
string UserId = 1;
string OperationID = 2;
}
message AlterUserResp{
CommonResp commonResp = 1;
}
message GetUserReq{
string OperationID = 1;
}
message GetUsersResp{
string OperationID = 1;
repeated Users User = 2;
}
message AddUserReq{
string OperationID = 1;
}
message AddUserResp{
CommonResp commonResp = 1;
}
service user {
rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp);
@ -116,4 +163,13 @@ service user {
rpc GetReceiveMessageOpt(GetReceiveMessageOptReq)returns(GetReceiveMessageOptResp);
rpc GetAllConversationMsgOpt(GetAllConversationMsgOptReq)returns(GetAllConversationMsgOptResp);
rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp);
rpc ResignUser(ResignUserReq) returns (ResignUserResp);
rpc GetUser(GetUserReq) returns (GetUserResp);
rpc AlterUser(AlterUserReq) returns (AlterUserResp);
rpc GetUsers(GetUsersReq) returns (GetUsersResp);
rpc AddUser(AddUserReq) returns (AddUserResp);
rpc BlockUser(BlockUserReq) returns (BlockUserResp);
rpc UnBlockUser(UnBlockUserReq) returns (UnBlockUserResp);
rpc GetBlockUsers(GetBlockUsersReq) returns (GetBlockUsersResp);
}

Loading…
Cancel
Save