You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
2 years ago
|
package controller
|
||
2 years ago
|
|
||
|
import (
|
||
|
"Open_IM/pkg/common/db/cache"
|
||
|
"Open_IM/pkg/common/db/mysql"
|
||
2 years ago
|
"Open_IM/pkg/common/db/relation"
|
||
2 years ago
|
"context"
|
||
|
"errors"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type FriendModel struct {
|
||
2 years ago
|
db *relation.Friend
|
||
2 years ago
|
cache *cache.GroupCache
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) Create(ctx context.Context, friends []*relation.Friend) (err error) {
|
||
2 years ago
|
return f.db.Create(ctx, friends)
|
||
|
}
|
||
|
|
||
|
func (f *FriendModel) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||
|
return f.db.Delete(ctx, ownerUserID, friendUserIDs)
|
||
|
}
|
||
|
|
||
|
func (f *FriendModel) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||
|
return f.db.UpdateByMap(ctx, ownerUserID, args)
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) Update(ctx context.Context, friends []*relation.Friend) (err error) {
|
||
2 years ago
|
return f.db.Update(ctx, friends)
|
||
|
}
|
||
|
|
||
|
func (f *FriendModel) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||
|
return f.db.UpdateRemark(ctx, ownerUserID, friendUserID, remark)
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error) {
|
||
2 years ago
|
return f.db.FindOwnerUserID(ctx, ownerUserID)
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error) {
|
||
2 years ago
|
return f.db.FindFriendUserID(ctx, friendUserID)
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error) {
|
||
2 years ago
|
return f.db.Take(ctx, ownerUserID, friendUserID)
|
||
|
}
|
||
|
|
||
2 years ago
|
func (f *FriendModel) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error) {
|
||
2 years ago
|
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
|
||
|
}
|
||
|
}
|