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.
Open-IM-Server/pkg/common/db/controller/black.go

53 lines
1.5 KiB

2 years ago
package controller
2 years ago
import (
"Open_IM/pkg/common/db/cache"
"Open_IM/pkg/common/db/mysql"
"context"
2 years ago
"errors"
"gorm.io/gorm"
2 years ago
)
type BlackModel struct {
2 years ago
db *relation.Black
2 years ago
cache *cache.GroupCache
}
2 years ago
func (b *BlackModel) Create(ctx context.Context, blacks []*relation.Black) (err error) {
2 years ago
return b.db.Create(ctx, blacks)
}
2 years ago
func (b *BlackModel) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
2 years ago
return b.db.Delete(ctx, blacks)
}
func (b *BlackModel) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
return b.db.UpdateByMap(ctx, ownerUserID, blockUserID, args)
}
2 years ago
func (b *BlackModel) Update(ctx context.Context, blacks []*relation.Black) (err error) {
2 years ago
return b.db.Update(ctx, blacks)
}
2 years ago
func (b *BlackModel) Find(ctx context.Context, blacks []*relation.Black) (blackList []*relation.Black, err error) {
2 years ago
return b.db.Find(ctx, blacks)
}
2 years ago
func (b *BlackModel) Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.Black, err error) {
2 years ago
return b.db.Take(ctx, ownerUserID, blockUserID)
2 years ago
}
2 years ago
func (b *BlackModel) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*relation.Black, err error) {
2 years ago
return b.db.FindByOwnerUserID(ctx, ownerUserID)
}
2 years ago
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
}
}