fix version 1
This commit is contained in:
@@ -2,18 +2,23 @@ package basic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/social/group/internal/impl"
|
||||
"bsm/full/module/social/group/internal/models"
|
||||
pb "bsm/full/module/social/group/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"time"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 解散群组
|
||||
func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,8 +27,37 @@ func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusRepl
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
// 校验群组存在,且仅群主可解散
|
||||
var group models.GroupBasic
|
||||
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if group.PassportID != auth.ID {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// 软删除群组及其成员记录
|
||||
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
if e := tx.Where("identity=?", in.Identity).Delete(&models.GroupBasic{}).Error; e != nil {
|
||||
return e
|
||||
}
|
||||
if e := tx.Where("group_identity=?", in.Identity).Delete(&models.GroupMember{}).Error; e != nil {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.DataStatusReply{
|
||||
Data: vars.OK,
|
||||
|
||||
Reference in New Issue
Block a user