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/relation/group_request_model_k.go

67 lines
2.8 KiB

2 years ago
package relation
import (
2 years ago
"Open_IM/pkg/common/db/table/relation"
2 years ago
"Open_IM/pkg/common/tracelog"
"Open_IM/pkg/utils"
"context"
2 years ago
"gorm.io/gorm"
)
2 years ago
type GroupRequestGorm struct {
DB *gorm.DB
2 years ago
}
2 years ago
func NewGroupRequest(db *gorm.DB) *GroupRequestGorm {
return &GroupRequestGorm{
2 years ago
DB: db,
}
}
2 years ago
func (g *GroupRequestGorm) Create(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
}()
2 years ago
return utils.Wrap(getDBConn(g.DB, tx).Create(&groupRequests).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) Delete(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
}()
2 years ago
return utils.Wrap(getDBConn(g.DB, tx).Delete(&groupRequests).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
}()
2 years ago
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) Update(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
}()
2 years ago
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groupRequests).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) Find(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (resultGroupRequests []*relation.GroupRequestModel, err error) {
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
}()
var where [][]interface{}
for _, groupMember := range groupRequests {
where = append(where, []interface{}{groupMember.GroupID, groupMember.UserID})
}
2 years ago
return resultGroupRequests, utils.Wrap(getDBConn(g.DB, tx).Where("(group_id, user_id) in ?", where).Find(&resultGroupRequests).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupRequest *relation.GroupRequestModel, err error) {
groupRequest = &relation.GroupRequestModel{}
defer func() {
2 years ago
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
}()
2 years ago
return groupRequest, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
}