This commit is contained in:
withchao
2023-01-17 14:54:08 +08:00
parent 1d428785d1
commit 58866c1b41
8 changed files with 77 additions and 72 deletions
+12 -10
View File
@@ -16,25 +16,27 @@ type Friend struct {
AddSource int32 `gorm:"column:add_source"`
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
Ex string `gorm:"column:ex;size:1024"`
db *gorm.DB `gorm:"-"`
DB *gorm.DB `gorm:"-"`
}
func NewFriend(db *gorm.DB) *Friend {
return &Friend{db: db}
var friend Friend
friend.DB = initModel(db, friend)
return &friend
}
func (f *Friend) Create(ctx context.Context, friends []*Friend) (err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
}()
return utils.Wrap(f.db.Create(&friends).Error, "")
return utils.Wrap(f.DB.Create(&friends).Error, "")
}
func (f *Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
defer func() {
trace_log.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(&Friend{}).Error, "")
err = utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
return err
}
@@ -42,39 +44,39 @@ func (f *Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[s
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
}()
return utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
return utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
}
func (f *Friend) Update(ctx context.Context, friends []*Friend) (err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
}()
return utils.Wrap(f.db.Updates(&friends).Error, "")
return utils.Wrap(f.DB.Updates(&friends).Error, "")
}
func (f *Friend) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
}()
return utils.Wrap(f.db.Model(f).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
return utils.Wrap(f.DB.Model(f).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
}
func (f *Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
}()
return friends, utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
return friends, utils.Wrap(f.DB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
}
func (f *Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *Friend, err error) {
friend = &Friend{}
defer trace_log.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, "")
return friend, utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
}
func (f *Friend) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*Friend, err error) {
defer func() {
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
}()
return friends, utils.Wrap(f.db.Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
return friends, utils.Wrap(f.DB.Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
}