mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-09 20:49:52 +08:00
friend update
This commit is contained in:
parent
7c92de7899
commit
80bde864c1
@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/relation"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"context"
|
"context"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -95,7 +96,7 @@ type FriendDatabaseInterface interface {
|
|||||||
// AddFriendRequest 增加或者更新好友申请
|
// AddFriendRequest 增加或者更新好友申请
|
||||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||||
BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error)
|
BecomeFriend(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||||
// RefuseFriendRequest 拒绝好友申请
|
// RefuseFriendRequest 拒绝好友申请
|
||||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||||
// AgreeFriendRequest 同意好友申请
|
// AgreeFriendRequest 同意好友申请
|
||||||
|
@ -1,31 +1,22 @@
|
|||||||
package relation
|
package relation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendDB interface {
|
type FriendDB interface {
|
||||||
Create(ctx context.Context, friends []*FriendModel) (err error)
|
Create(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||||
Update(ctx context.Context, friends []*FriendModel) (err error)
|
Update(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*FriendModel, err error)
|
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FriendModel struct {
|
|
||||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
|
||||||
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
|
||||||
Remark string `gorm:"column:remark;size:255"`
|
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
|
||||||
AddSource int32 `gorm:"column:add_source"`
|
|
||||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
|
||||||
}
|
|
||||||
type FriendGorm struct {
|
type FriendGorm struct {
|
||||||
DB *gorm.DB `gorm:"-"`
|
DB *gorm.DB `gorm:"-"`
|
||||||
}
|
}
|
||||||
@ -39,7 +30,7 @@ type FriendUser struct {
|
|||||||
Nickname string `gorm:"column:name;size:255"`
|
Nickname string `gorm:"column:name;size:255"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) Create(ctx context.Context, friends []*FriendModel) (err error) {
|
func (f *FriendGorm) Create(ctx context.Context, friends []*table.FriendModel) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||||
}()
|
}()
|
||||||
@ -50,7 +41,7 @@ func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserI
|
|||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||||
}()
|
}()
|
||||||
err = utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&FriendModel{}).Error, "")
|
err = utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&table.FriendModel{}).Error, "")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +52,7 @@ func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, args m
|
|||||||
return utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
return utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) Update(ctx context.Context, friends []*FriendModel) (err error) {
|
func (f *FriendGorm) Update(ctx context.Context, friends []*table.FriendModel) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||||
}()
|
}()
|
||||||
@ -72,30 +63,30 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
|
|||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
||||||
}()
|
}()
|
||||||
return utils.Wrap(f.DB.Model(&FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*FriendModel, err error) {
|
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||||
}()
|
}()
|
||||||
return friends, utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
return friends, utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*FriendModel, err error) {
|
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*table.FriendModel, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||||
}()
|
}()
|
||||||
return friends, utils.Wrap(f.DB.Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
return friends, utils.Wrap(f.DB.Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *FriendModel, err error) {
|
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||||
friend = &FriendModel{}
|
friend = &table.FriendModel{}
|
||||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
||||||
return friend, utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
return friend, utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*FriendModel, err error) {
|
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*table.FriendModel, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
||||||
}()
|
}()
|
||||||
|
13
pkg/common/db/table/table.go
Normal file
13
pkg/common/db/table/table.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package table
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type FriendModel struct {
|
||||||
|
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||||
|
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||||
|
Remark string `gorm:"column:remark;size:255"`
|
||||||
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
|
AddSource int32 `gorm:"column:add_source"`
|
||||||
|
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||||
|
Ex string `gorm:"column:ex;size:1024"`
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user