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.go

53 lines
2.4 KiB

2 years ago
package relation
3 years ago
2 years ago
import (
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/ormutil"
2 years ago
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
2 years ago
"gorm.io/gorm"
)
type GroupRequestGorm struct {
2 years ago
*MetaDB
2 years ago
}
2 years ago
func NewGroupRequest(db *gorm.DB) relation.GroupRequestModelInterface {
2 years ago
return &GroupRequestGorm{
2 years ago
NewMetaDB(db, &relation.GroupRequestModel{}),
2 years ago
}
}
2 years ago
func (g *GroupRequestGorm) NewTx(tx any) relation.GroupRequestModelInterface {
return &GroupRequestGorm{NewMetaDB(tx.(*gorm.DB), &relation.GroupRequestModel{})}
2 years ago
}
2 years ago
func (g *GroupRequestGorm) Create(ctx context.Context, groupRequests []*relation.GroupRequestModel) (err error) {
2 years ago
return utils.Wrap(g.DB.WithContext(ctx).Create(&groupRequests).Error, utils.GetSelfFuncName())
}
func (g *GroupRequestGorm) Delete(ctx context.Context, groupID string, userID string) (err error) {
return utils.Wrap(g.DB.WithContext(ctx).Where("group_id = ? and user_id = ? ", groupID, userID).Delete(&relation.GroupRequestModel{}).Error, utils.GetSelfFuncName())
2 years ago
}
2 years ago
func (g *GroupRequestGorm) UpdateHandler(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32) (err error) {
2 years ago
return utils.Wrap(g.DB.WithContext(ctx).Model(&relation.GroupRequestModel{}).Where("group_id = ? and user_id = ? ", groupID, userID).Updates(map[string]any{
2 years ago
"handle_msg": handledMsg,
"handle_result": handleResult,
}).Error, utils.GetSelfFuncName())
}
2 years ago
func (g *GroupRequestGorm) Take(ctx context.Context, groupID string, userID string) (groupRequest *relation.GroupRequestModel, err error) {
2 years ago
groupRequest = &relation.GroupRequestModel{}
2 years ago
return groupRequest, utils.Wrap(g.DB.WithContext(ctx).Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
2 years ago
}
2 years ago
func (g *GroupRequestGorm) Page(ctx context.Context, userID string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupRequestModel, err error) {
2 years ago
return ormutil.GormSearch[relation.GroupRequestModel](g.DB.WithContext(ctx).Where("user_id = ?", userID), nil, "", pageNumber, showNumber)
2 years ago
}
2 years ago
func (g *GroupRequestGorm) PageGroup(ctx context.Context, groupIDs []string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupRequestModel, err error) {
2 years ago
return ormutil.GormPage[relation.GroupRequestModel](g.DB.WithContext(ctx).Where("group_id in ?", groupIDs), pageNumber, showNumber)
2 years ago
}