parent
d9eb55d9df
commit
ec23d22d6d
@ -1,52 +1,90 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BlackModel struct {
|
||||
db *relation.Black
|
||||
cache *cache.GroupCache
|
||||
type BlackInterface interface {
|
||||
Create(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
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)
|
||||
}
|
||||
|
||||
func (b *BlackModel) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.db.Create(ctx, blacks)
|
||||
type BlackController struct {
|
||||
database BlackDatabaseInterface
|
||||
}
|
||||
|
||||
func (b *BlackModel) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.db.Delete(ctx, blacks)
|
||||
func NewBlackController(db *gorm.DB) *BlackController {
|
||||
return &BlackController{database: NewBlackDatabase(db)}
|
||||
}
|
||||
|
||||
func (b *BlackModel) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||
return b.db.UpdateByMap(ctx, ownerUserID, blockUserID, args)
|
||||
func (f *BlackController) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.database.Create(ctx, blacks)
|
||||
}
|
||||
|
||||
func (b *BlackModel) Update(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.db.Update(ctx, blacks)
|
||||
func (f *BlackController) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.database.Delete(ctx, blacks)
|
||||
}
|
||||
|
||||
func (b *BlackModel) Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error) {
|
||||
return b.db.Find(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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
func (b *BlackModel) Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error) {
|
||||
return b.db.Take(ctx, ownerUserID, blockUserID)
|
||||
type BlackDatabaseInterface interface {
|
||||
Create(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
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)
|
||||
}
|
||||
|
||||
func (b *BlackModel) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error) {
|
||||
return b.db.FindByOwnerUserID(ctx, ownerUserID)
|
||||
type BlackDatabase struct {
|
||||
sqlDB *relation.Black
|
||||
}
|
||||
|
||||
func (b *BlackModel) IsExist(ctx context.Context, ownerUserID, blockUserID string) (bool, error) {
|
||||
if _, err := b.Take(ctx, ownerUserID, blockUserID); err == nil {
|
||||
return true, nil
|
||||
} else if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
} else {
|
||||
return false, err
|
||||
func NewBlackDatabase(db *gorm.DB) *BlackDatabase {
|
||||
sqlDB := relation.NewBlack(db)
|
||||
database := &BlackDatabase{
|
||||
sqlDB: sqlDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
func (f *BlackDatabase) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.sqlDB.Create(ctx, blacks)
|
||||
}
|
||||
func (f *BlackDatabase) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return f.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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
@ -1,44 +1,110 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FriendRequestModel struct {
|
||||
db *relation.FriendRequest
|
||||
cache *cache.GroupCache
|
||||
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)
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) Create(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.db.Create(ctx, friends)
|
||||
type FriendRequestController struct {
|
||||
database FriendRequestInterface
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
return f.db.Delete(ctx, fromUserID, toUserID)
|
||||
func NewFriendRequestController(db *gorm.DB) *FriendRequestController {
|
||||
return &FriendRequestController{database: NewFriendRequestDatabase(db)}
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
return f.db.UpdateByMap(ctx, ownerUserID, args)
|
||||
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)
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) Update(ctx context.Context, friends []*relation.FriendRequest) (err error) {
|
||||
return f.db.Update(ctx, friends)
|
||||
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)
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.db.Find(ctx, ownerUserID)
|
||||
type FriendRequestDatabase struct {
|
||||
sqlDB *relation.FriendRequest
|
||||
friend *FriendDatabase
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequest, err error) {
|
||||
return f.db.Take(ctx, fromUserID, toUserID)
|
||||
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 (f *FriendRequestModel) FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.db.FindToUserID(ctx, toUserID)
|
||||
func NewFriendRequestDatabase(db *gorm.DB) *FriendRequestDatabase {
|
||||
sqlDB := relation.NewFriendRequest(db)
|
||||
database := &FriendRequestDatabase{
|
||||
sqlDB: sqlDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
func (f *FriendRequestModel) FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequest, err error) {
|
||||
return f.db.FindFromUserID(ctx, fromUserID)
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in new issue