mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 11:40:01 +08:00
friend update
This commit is contained in:
parent
7c92de7899
commit
80bde864c1
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@ -95,7 +96,7 @@ type FriendDatabaseInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
BecomeFriend(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
|
@ -1,31 +1,22 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
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)
|
||||
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)
|
||||
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 {
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
@ -39,7 +30,7 @@ type FriendUser struct {
|
||||
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() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
@ -50,7 +41,7 @@ func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserI
|
||||
defer func() {
|
||||
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
|
||||
}
|
||||
|
||||
@ -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, "")
|
||||
}
|
||||
|
||||
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() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
@ -72,30 +63,30 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
|
||||
defer func() {
|
||||
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() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
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() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
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) {
|
||||
friend = &FriendModel{}
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||
friend = &table.FriendModel{}
|
||||
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, "")
|
||||
}
|
||||
|
||||
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() {
|
||||
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