mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 16:15:59 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
This commit is contained in:
@@ -3,17 +3,19 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BlackInterface interface {
|
||||
// Create 增加黑名单
|
||||
Create(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error)
|
||||
Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error)
|
||||
FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackController struct {
|
||||
@@ -23,36 +25,36 @@ type BlackController struct {
|
||||
func NewBlackController(db *gorm.DB) *BlackController {
|
||||
return &BlackController{database: NewBlackDatabase(db)}
|
||||
}
|
||||
func (f *BlackController) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.database.Create(ctx, blacks)
|
||||
|
||||
// Create 增加黑名单
|
||||
func (b *BlackController) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Create(ctx, blacks)
|
||||
}
|
||||
func (f *BlackController) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.database.Delete(ctx, blacks)
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackController) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Delete(ctx, blacks)
|
||||
}
|
||||
func (f *BlackController) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||
return f.database.UpdateByMap(ctx, ownerUserID, blockUserID, args)
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackController) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, total int64, err error) {
|
||||
return b.database.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
func (f *BlackController) Update(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.database.Update(ctx, blacks)
|
||||
}
|
||||
func (f *BlackController) Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error) {
|
||||
return f.database.Find(ctx, blacks)
|
||||
}
|
||||
func (f *BlackController) Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error) {
|
||||
return f.database.Take(ctx, ownerUserID, blockUserID)
|
||||
}
|
||||
func (f *BlackController) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error) {
|
||||
return f.database.FindByOwnerUserID(ctx, ownerUserID)
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackController) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
return b.database.CheckIn(ctx, userID1, userID2)
|
||||
}
|
||||
|
||||
type BlackDatabaseInterface interface {
|
||||
// Create 增加黑名单
|
||||
Create(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error)
|
||||
Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error)
|
||||
FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackDatabase struct {
|
||||
@@ -67,24 +69,42 @@ func NewBlackDatabase(db *gorm.DB) *BlackDatabase {
|
||||
return database
|
||||
}
|
||||
|
||||
func (f *BlackDatabase) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.sqlDB.Create(ctx, blacks)
|
||||
// Create 增加黑名单
|
||||
func (b *BlackDatabase) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Create(ctx, blacks)
|
||||
}
|
||||
func (f *BlackDatabase) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.sqlDB.Delete(ctx, blacks)
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackDatabase) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Delete(ctx, blacks)
|
||||
}
|
||||
func (f *BlackDatabase) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||
return f.sqlDB.UpdateByMap(ctx, ownerUserID, blockUserID, args)
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackDatabase) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error) {
|
||||
return b.sqlDB.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
func (f *BlackDatabase) Update(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.sqlDB.Update(ctx, blacks)
|
||||
}
|
||||
func (f *BlackDatabase) Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error) {
|
||||
return f.sqlDB.Find(ctx, blacks)
|
||||
}
|
||||
func (f *BlackDatabase) Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error) {
|
||||
return f.sqlDB.Take(ctx, ownerUserID, blockUserID)
|
||||
}
|
||||
func (f *BlackDatabase) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error) {
|
||||
return f.sqlDB.FindByOwnerUserID(ctx, ownerUserID)
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
_, err = b.sqlDB.Take(ctx, userID1, userID2)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser1Blacks = false
|
||||
} else {
|
||||
inUser1Blacks = true
|
||||
}
|
||||
|
||||
inUser2Blacks = true
|
||||
_, err = b.sqlDB.Take(ctx, userID2, userID1)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser2Blacks = false
|
||||
} else {
|
||||
inUser2Blacks = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,25 +7,30 @@ import (
|
||||
)
|
||||
|
||||
type FriendInterface interface {
|
||||
// CheckIn 检查fromUserID是否在toUserID的好友列表中(inTo==true) 检查toUserID是否在fromUserID的好友列表中(inFrom==true)
|
||||
CheckIn(ctx context.Context, fromUserID, toUserID string) (err error, inTo bool, inFrom bool)
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
CheckIn(ctx context.Context, user1, user2 string) (err error, inUser1Friends bool, inUser2Friends bool)
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// 先判断是否在好友表,如果在则不插入
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
//拒绝好友申请
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||
// 同意好友申请
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||
Create(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
// Delete 删除好友
|
||||
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 更新好友备注
|
||||
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)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error)
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.Friend, err error)
|
||||
}
|
||||
|
||||
type FriendController struct {
|
||||
@@ -36,44 +41,79 @@ func NewFriendController(db *gorm.DB) *FriendController {
|
||||
return &FriendController{database: NewFriendDatabase(db)}
|
||||
}
|
||||
|
||||
func (f *FriendController) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||
return f.database.Create(ctx, friends)
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
func (f *FriendController) CheckIn(ctx context.Context, user1, user2 string) (err error, inUser1Friends bool, inUser2Friends bool) {
|
||||
}
|
||||
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
func (f *FriendController) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) {
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error) {
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error) {
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
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)
|
||||
}
|
||||
|
||||
// UpdateRemark 更新好友备注
|
||||
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)
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
func (f *FriendController) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
||||
return f.database.FindFriendUserID(ctx, friendUserID)
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
func (f *FriendController) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
||||
return f.database.Take(ctx, ownerUserID, friendUserID)
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error) {
|
||||
}
|
||||
func (f *FriendController) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
||||
return f.database.FindUserState(ctx, userID1, userID2)
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error) {
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
|
||||
type FriendDatabaseInterface interface {
|
||||
Create(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
CheckIn(ctx context.Context, user1, user2 string) (err error, inUser1Friends bool, inUser2Friends bool)
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error)
|
||||
// Delete 删除好友
|
||||
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 更新好友备注
|
||||
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)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error)
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.Friend, err error)
|
||||
}
|
||||
|
||||
type FriendDatabase struct {
|
||||
@@ -88,30 +128,50 @@ func NewFriendDatabase(db *gorm.DB) *FriendDatabase {
|
||||
return database
|
||||
}
|
||||
|
||||
func (f *FriendDatabase) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||
return f.sqlDB.Create(ctx, friends)
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
func (f *FriendDatabase) CheckIn(ctx context.Context, user1, user2 string) (err error, inUser1Friends bool, inUser2Friends bool) {
|
||||
}
|
||||
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) {
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, friends []*relation.Friend) (err error) {
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error) {
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequest) (err error) {
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
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)
|
||||
}
|
||||
|
||||
// UpdateRemark 更新好友备注
|
||||
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)
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
func (f *FriendDatabase) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
||||
return f.sqlDB.FindFriendUserID(ctx, friendUserID)
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
func (f *FriendDatabase) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
||||
return f.sqlDB.Take(ctx, ownerUserID, friendUserID)
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error) {
|
||||
}
|
||||
func (f *FriendDatabase) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
||||
return f.sqlDB.FindUserState(ctx, userID1, userID2)
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequest, err error) {
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.Friend, err error) {
|
||||
}
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FriendRequestInterface interface {
|
||||
Create(ctx context.Context, friends []*relation.FriendRequest) (err error)
|
||||
Delete(ctx context.Context, fromUserID, toUserID string) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*relation.FriendRequest) (err error)
|
||||
Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequest, err error)
|
||||
Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequest, err error)
|
||||
FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequest, err error)
|
||||
FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequest, err error)
|
||||
}
|
||||
|
||||
type FriendRequestController struct {
|
||||
database FriendRequestInterface
|
||||
}
|
||||
|
||||
func NewFriendRequestController(db *gorm.DB) *FriendRequestController {
|
||||
return &FriendRequestController{database: NewFriendRequestDatabase(db)}
|
||||
}
|
||||
|
||||
func (f *FriendRequestController) Create(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.database.Create(ctx, friends)
|
||||
}
|
||||
func (f *FriendRequestController) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
return f.database.Delete(ctx, fromUserID, toUserID)
|
||||
}
|
||||
func (f *FriendRequestController) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
return f.database.UpdateByMap(ctx, ownerUserID, args)
|
||||
}
|
||||
func (f *FriendRequestController) Update(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.database.Update(ctx, friends)
|
||||
}
|
||||
func (f *FriendRequestController) Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.database.Find(ctx, ownerUserID)
|
||||
}
|
||||
func (f *FriendRequestController) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequest, err error) {
|
||||
return f.database.Take(ctx, fromUserID, toUserID)
|
||||
}
|
||||
func (f *FriendRequestController) FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.database.FindToUserID(ctx, toUserID)
|
||||
}
|
||||
func (f *FriendRequestController) FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.database.FindFromUserID(ctx, fromUserID)
|
||||
}
|
||||
|
||||
type FriendRequestDatabaseInterface interface {
|
||||
Create(ctx context.Context, friends []*relation.FriendRequest) (err error)
|
||||
Delete(ctx context.Context, fromUserID, toUserID string) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*relation.FriendRequest) (err error)
|
||||
Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequest, err error)
|
||||
Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequest, err error)
|
||||
FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequest, err error)
|
||||
FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequest, err error)
|
||||
}
|
||||
|
||||
type FriendRequestDatabase struct {
|
||||
sqlDB *relation.FriendRequest
|
||||
friend *FriendDatabase
|
||||
}
|
||||
|
||||
func (f *FriendRequestDatabase) Update(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.sqlDB.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := f.sqlDB.Update(ctx, friends); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.friend.Update(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewFriendRequestDatabase(db *gorm.DB) *FriendRequestDatabase {
|
||||
sqlDB := relation.NewFriendRequest(db)
|
||||
database := &FriendRequestDatabase{
|
||||
sqlDB: sqlDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
func (f *FriendRequestDatabase) Create(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.sqlDB.Create(ctx, friends)
|
||||
}
|
||||
func (f *FriendRequestDatabase) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
return f.sqlDB.Delete(ctx, fromUserID, toUserID)
|
||||
}
|
||||
func (f *FriendRequestDatabase) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
return f.sqlDB.UpdateByMap(ctx, ownerUserID, args)
|
||||
}
|
||||
|
||||
func (f *FriendRequestDatabase) Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.sqlDB.Find(ctx, ownerUserID)
|
||||
}
|
||||
func (f *FriendRequestDatabase) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequest, err error) {
|
||||
return f.sqlDB.Take(ctx, fromUserID, toUserID)
|
||||
}
|
||||
func (f *FriendRequestDatabase) FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.sqlDB.FindToUserID(ctx, toUserID)
|
||||
}
|
||||
func (f *FriendRequestDatabase) FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.sqlDB.FindFromUserID(ctx, fromUserID)
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type UserInterface interface {
|
||||
//获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation.User, err error)
|
||||
Create(ctx context.Context, users []*relation.User) error
|
||||
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, count int64, err error)
|
||||
|
||||
@@ -71,44 +71,14 @@ func (b *Black) Take(ctx context.Context, ownerUserID, blockUserID string) (blac
|
||||
return black, utils.Wrap(b.DB.Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
||||
func (b *Black) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*Black, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blackList", blackList)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blacks", blacks)
|
||||
}()
|
||||
return blackList, utils.Wrap(GroupMemberDB.Where("owner_user_id = ?", ownerUserID).Find(&blackList).Error, "")
|
||||
}
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black Black) (err error) {
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "black", black)
|
||||
black.CreateTime = time.Now()
|
||||
err = BlackDB.Create(black).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
var black Black
|
||||
return BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
}
|
||||
|
||||
func RemoveBlackList(ownerUserID, blockUserID string) error {
|
||||
err := BlackDB.Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(Black{}).Error
|
||||
return utils.Wrap(err, "RemoveBlackList failed")
|
||||
}
|
||||
|
||||
func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
|
||||
var blackListUsersInfo []Black
|
||||
err := BlackDB.Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
err = b.DB.Model(b).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
return blackListUsersInfo, nil
|
||||
}
|
||||
|
||||
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
|
||||
var blackIDList []string
|
||||
err := b.db.Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return blackIDList, nil
|
||||
err = utils.Wrap(b.DB.Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user