mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-13 15:25:03 +08:00
Error code standardization
This commit is contained in:
parent
2a76dc3ac8
commit
f38dc3b1f1
@ -4,8 +4,9 @@ import (
|
|||||||
chat "Open_IM/internal/rpc/msg"
|
chat "Open_IM/internal/rpc/msg"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db/model"
|
"Open_IM/pkg/common/db/controller"
|
||||||
"Open_IM/pkg/common/db/mysql"
|
|
||||||
|
"Open_IM/pkg/common/db/relation"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/common/middleware"
|
"Open_IM/pkg/common/middleware"
|
||||||
promePkg "Open_IM/pkg/common/prometheus"
|
promePkg "Open_IM/pkg/common/prometheus"
|
||||||
@ -34,27 +35,34 @@ type friendServer struct {
|
|||||||
rpcRegisterName string
|
rpcRegisterName string
|
||||||
etcdSchema string
|
etcdSchema string
|
||||||
etcdAddr []string
|
etcdAddr []string
|
||||||
friendModel *controller.FriendModel
|
controller.FriendInterface
|
||||||
friendRequestModel *controller.FriendRequestModel
|
|
||||||
blackModel *controller.BlackModel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFriendServer(port int) *friendServer {
|
func NewFriendServer(port int) *friendServer {
|
||||||
log.NewPrivateLog(constant.LogFileName)
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &friendServer{
|
f := friendServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||||
}
|
}
|
||||||
|
//mysql init
|
||||||
|
var mysql relation.Mysql
|
||||||
|
var model relation.Friend
|
||||||
|
err := mysql.InitConn().AutoMigrateModel(&model)
|
||||||
|
if err != nil {
|
||||||
|
panic("db init err:" + err.Error())
|
||||||
|
}
|
||||||
|
if mysql.GormConn() != nil {
|
||||||
|
model.DB = mysql.GormConn()
|
||||||
|
} else {
|
||||||
|
panic("db init err:" + "conn is nil")
|
||||||
|
}
|
||||||
|
f.FriendInterface = controller.NewFriendController(model.DB)
|
||||||
|
return &f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *friendServer) Run() {
|
func (s *friendServer) Run() {
|
||||||
db := relation.ConnectToDB()
|
|
||||||
//s.friendModel = mysql.NewFriend(db)
|
|
||||||
//s.friendRequestModel = mysql.NewFriendRequest(db)
|
|
||||||
//s.blackModel = mysql.NewBlack(db)
|
|
||||||
|
|
||||||
log.NewInfo("0", "friendServer run...")
|
log.NewInfo("0", "friendServer run...")
|
||||||
|
|
||||||
listenIP := ""
|
listenIP := ""
|
||||||
|
@ -1,60 +1,107 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/db/cache"
|
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/relation"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendModel struct {
|
type FriendInterface interface {
|
||||||
db *relation.Friend
|
Create(ctx context.Context, friends []*relation.Friend) (err error)
|
||||||
cache *cache.GroupCache
|
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||||
|
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||||
|
Update(ctx context.Context, friends []*relation.Friend) (err error)
|
||||||
|
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||||
|
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error)
|
||||||
|
FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error)
|
||||||
|
Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error)
|
||||||
|
FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
type FriendController struct {
|
||||||
return f.db.Create(ctx, friends)
|
database FriendDatabaseInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
func NewFriendController(db *gorm.DB) *FriendController {
|
||||||
return f.db.Delete(ctx, ownerUserID, friendUserIDs)
|
return &FriendController{database: NewFriendDatabase(db)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
func (f *FriendController) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||||
return f.db.UpdateByMap(ctx, ownerUserID, args)
|
return f.database.Create(ctx, friends)
|
||||||
|
}
|
||||||
|
func (f *FriendController) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||||
|
return f.database.Delete(ctx, ownerUserID, friendUserIDs)
|
||||||
|
}
|
||||||
|
func (f *FriendController) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||||
|
return f.database.UpdateByMap(ctx, ownerUserID, args)
|
||||||
|
}
|
||||||
|
func (f *FriendController) Update(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||||
|
return f.database.Update(ctx, friends)
|
||||||
|
}
|
||||||
|
func (f *FriendController) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||||
|
return f.database.UpdateRemark(ctx, ownerUserID, friendUserID, remark)
|
||||||
|
}
|
||||||
|
func (f *FriendController) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.database.FindOwnerUserID(ctx, ownerUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendController) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.database.FindFriendUserID(ctx, friendUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendController) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
||||||
|
return f.database.Take(ctx, ownerUserID, friendUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendController) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.database.FindUserState(ctx, userID1, userID2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) Update(ctx context.Context, friends []*relation.Friend) (err error) {
|
type FriendDatabaseInterface interface {
|
||||||
return f.db.Update(ctx, friends)
|
Create(ctx context.Context, friends []*relation.Friend) (err error)
|
||||||
|
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||||
|
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||||
|
Update(ctx context.Context, friends []*relation.Friend) (err error)
|
||||||
|
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||||
|
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error)
|
||||||
|
FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error)
|
||||||
|
Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error)
|
||||||
|
FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
type FriendDatabase struct {
|
||||||
return f.db.UpdateRemark(ctx, ownerUserID, friendUserID, remark)
|
sqlDB *relation.Friend
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendModel) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error) {
|
func NewFriendDatabase(db *gorm.DB) *FriendDatabase {
|
||||||
return f.db.FindOwnerUserID(ctx, ownerUserID)
|
sqlDB := relation.NewFriendDB(db)
|
||||||
}
|
database := &FriendDatabase{
|
||||||
|
sqlDB: sqlDB,
|
||||||
func (f *FriendModel) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
|
||||||
return f.db.FindFriendUserID(ctx, friendUserID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendModel) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
|
||||||
return f.db.Take(ctx, ownerUserID, friendUserID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendModel) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
|
||||||
return f.db.FindUserState(ctx, userID1, userID2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendModel) IsExist(ctx context.Context, ownerUserID, friendUserID string) (bool, error) {
|
|
||||||
if _, err := f.Take(ctx, ownerUserID, friendUserID); err == nil {
|
|
||||||
return true, nil
|
|
||||||
} else if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return false, nil
|
|
||||||
} else {
|
|
||||||
return false, err
|
|
||||||
}
|
}
|
||||||
|
return database
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FriendDatabase) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||||
|
return f.sqlDB.Create(ctx, friends)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||||
|
return f.sqlDB.Delete(ctx, ownerUserID, friendUserIDs)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||||
|
return f.sqlDB.UpdateByMap(ctx, ownerUserID, args)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) Update(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||||
|
return f.sqlDB.Update(ctx, friends)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||||
|
return f.sqlDB.UpdateRemark(ctx, ownerUserID, friendUserID, remark)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.sqlDB.FindOwnerUserID(ctx, ownerUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.sqlDB.FindFriendUserID(ctx, friendUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
||||||
|
return f.sqlDB.Take(ctx, ownerUserID, friendUserID)
|
||||||
|
}
|
||||||
|
func (f *FriendDatabase) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
||||||
|
return f.sqlDB.FindUserState(ctx, userID1, userID2)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (u *UserController) GetByNameAndID(ctx context.Context, content string, sho
|
|||||||
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error) {
|
||||||
return u.database.Get(ctx, showNumber, pageNumber)
|
return u.database.Get(ctx, showNumber, pageNumber)
|
||||||
}
|
}
|
||||||
func NewUserController(db *gorm.DB) UserInterface {
|
func NewUserController(db *gorm.DB) *UserController {
|
||||||
controller := &UserController{database: newUserDatabase(db)}
|
controller := &UserController{database: newUserDatabase(db)}
|
||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
@ -58,14 +58,14 @@ type UserDatabaseInterface interface {
|
|||||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (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, count int64, 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)
|
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)
|
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserDatabase struct {
|
type UserDatabase struct {
|
||||||
sqlDB *relation.User
|
sqlDB *relation.User
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserDatabase(db *gorm.DB) UserDatabaseInterface {
|
func newUserDatabase(db *gorm.DB) *UserDatabase {
|
||||||
sqlDB := relation.NewUserDB(db)
|
sqlDB := relation.NewUserDB(db)
|
||||||
database := &UserDatabase{
|
database := &UserDatabase{
|
||||||
sqlDB: sqlDB,
|
sqlDB: sqlDB,
|
||||||
|
@ -19,7 +19,7 @@ type Friend struct {
|
|||||||
DB *gorm.DB `gorm:"-"`
|
DB *gorm.DB `gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFriend(db *gorm.DB) *Friend {
|
func NewFriendDB(db *gorm.DB) *Friend {
|
||||||
var friend Friend
|
var friend Friend
|
||||||
friend.DB = initModel(db, friend)
|
friend.DB = initModel(db, friend)
|
||||||
return &friend
|
return &friend
|
||||||
|
Loading…
x
Reference in New Issue
Block a user