mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-30 23:33:06 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AdminCMSInterface interface {
|
||||
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalUserNum() (num int64, err error)
|
||||
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalGroupNum() (num int64, err error)
|
||||
GetGroupNum(to time.Time) (num int64, err error)
|
||||
GetActiveGroups(from, to time.Time, limit int) (activeGroups []*relation.ActiveGroup, err error)
|
||||
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||
}
|
||||
|
||||
type AdminCMSController struct {
|
||||
database AdminCMSDatabaseInterface
|
||||
}
|
||||
|
||||
func NewAdminCMSController(db *gorm.DB) AdminCMSInterface {
|
||||
adminCMSController := &AdminCMSController{
|
||||
database: newAdminCMSDatabase(db),
|
||||
}
|
||||
return adminCMSController
|
||||
}
|
||||
|
||||
func newAdminCMSDatabase(db *gorm.DB) AdminCMSDatabaseInterface {
|
||||
return &AdminCMSDatabase{Statistics: relation.NewStatistics(db)}
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetActiveUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetIncreaseUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalUserNum() (num int64, err error) {
|
||||
return admin.database.GetTotalUserNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||
return admin.database.GetTotalUserNumByDate(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.GetSingleChatMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetGroupMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.database.GetIncreaseGroupNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetTotalGroupNum() (num int64, err error) {
|
||||
return admin.database.GetTotalGroupNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
return admin.database.GetGroupNum(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||
return admin.database.GetActiveGroups(from, to, limit)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSController) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||
return admin.database.GetActiveUsers(from, to, limit)
|
||||
}
|
||||
|
||||
type AdminCMSDatabaseInterface interface {
|
||||
GetActiveUserNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseUserNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalUserNum() (num int64, err error)
|
||||
GetTotalUserNumByDate(to time.Time) (num int64, err error)
|
||||
GetSingleChatMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetGroupMessageNum(from, to time.Time) (num int64, err error)
|
||||
GetIncreaseGroupNum(from, to time.Time) (num int64, err error)
|
||||
GetTotalGroupNum() (num int64, err error)
|
||||
GetGroupNum(to time.Time) (num int64, err error)
|
||||
GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error)
|
||||
GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error)
|
||||
}
|
||||
|
||||
type AdminCMSDatabase struct {
|
||||
Statistics *relation.Statistics
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetActiveUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetIncreaseUserNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetIncreaseUserNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalUserNum() (num int64, err error) {
|
||||
return admin.Statistics.GetTotalUserNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalUserNumByDate(to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetTotalUserNumByDate(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetSingleChatMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetSingleChatMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetGroupMessageNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetGroupMessageNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetIncreaseGroupNum(from, to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetIncreaseGroupNum(from, to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetTotalGroupNum() (num int64, err error) {
|
||||
return admin.Statistics.GetTotalGroupNum()
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetGroupNum(to time.Time) (num int64, err error) {
|
||||
return admin.Statistics.GetGroupNum(to)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveGroups(from, to time.Time, limit int) ([]*relation.ActiveGroup, error) {
|
||||
return admin.Statistics.GetActiveGroups(from, to, limit)
|
||||
}
|
||||
|
||||
func (admin *AdminCMSDatabase) GetActiveUsers(from, to time.Time, limit int) (activeUsers []*relation.ActiveUser, err error) {
|
||||
return admin.Statistics.GetActiveUsers(from, to, limit)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ type GroupInterface interface {
|
||||
}
|
||||
|
||||
type GroupController struct {
|
||||
database DataBase
|
||||
database GroupDataBaseInterface
|
||||
}
|
||||
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
|
||||
@@ -65,16 +65,10 @@ func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string,
|
||||
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
||||
}
|
||||
|
||||
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation.Group, error) {
|
||||
return g.database.GetJoinedGroupList(ctx, userID)
|
||||
}
|
||||
|
||||
type DataBase interface {
|
||||
type GroupDataBaseInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
|
||||
CreateGroup(ctx context.Context, groups []*relation.Group, groupMember []*relation.GroupMember) error
|
||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||
GetJoinedGroupList(ctx context.Context, userID string) ([]*relation.Group, error)
|
||||
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error)
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
@@ -90,7 +84,7 @@ type GroupDataBase struct {
|
||||
mongoDB *unrelation.SuperGroupMgoDB
|
||||
}
|
||||
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) DataBase {
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupDataBaseInterface {
|
||||
groupDB := relation.NewGroupDB(db)
|
||||
groupMemberDB := relation.NewGroupMemberDB(db)
|
||||
groupRequestDB := relation.NewGroupRequest(db)
|
||||
|
||||
@@ -12,7 +12,9 @@ type UserInterface interface {
|
||||
Take(ctx context.Context, userID string) (user *relation.User, err error)
|
||||
Update(ctx context.Context, users []*relation.User) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
}
|
||||
|
||||
type UserController struct {
|
||||
@@ -34,10 +36,15 @@ func (u *UserController) Update(ctx context.Context, users []*relation.User) (er
|
||||
func (u *UserController) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return u.database.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error) {
|
||||
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.database.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.database.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
}
|
||||
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.database.Get(ctx, showNumber, pageNumber)
|
||||
}
|
||||
func NewUserController(db *gorm.DB) UserInterface {
|
||||
controller := &UserController{database: newUserDatabase(db)}
|
||||
return controller
|
||||
@@ -49,7 +56,9 @@ type UserDatabaseInterface interface {
|
||||
Take(ctx context.Context, userID string) (user *relation.User, err error)
|
||||
Update(ctx context.Context, users []*relation.User) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*User, count int64, err error)
|
||||
}
|
||||
|
||||
type UserDatabase struct {
|
||||
@@ -80,6 +89,12 @@ func (u *UserDatabase) Update(ctx context.Context, users []*relation.User) (err
|
||||
func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return u.sqlDB.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, err error) {
|
||||
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.sqlDB.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
func (u *UserDatabase) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.sqlDB.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
}
|
||||
func (u *UserDatabase) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||
return u.sqlDB.Get(ctx, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user