first commit
This commit is contained in:
60
service/group/logic/set_admin.go
Normal file
60
service/group/logic/set_admin.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/chat/dtalk/service/group/model/biz"
|
||||
"gitlab.33.cn/chat/dtalk/service/group/service"
|
||||
)
|
||||
|
||||
type SetAdminLogic struct {
|
||||
ctx context.Context
|
||||
svc *service.Service
|
||||
}
|
||||
|
||||
func NewSetAdminLogic(ctx context.Context, svc *service.Service) *SetAdminLogic {
|
||||
return &SetAdminLogic{
|
||||
ctx: ctx,
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// SetAdmin 设置管理员
|
||||
func (l *SetAdminLogic) SetAdmin(req *pb.SetAdminReq) (*pb.SetAdminResp, error) {
|
||||
groupId := req.GroupId
|
||||
personId := req.PersonId
|
||||
memberId := req.MemberId
|
||||
memberType := int32(req.GroupMemberType)
|
||||
|
||||
group, err := l.svc.GetGroupInfoByGroupId(l.ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
person, err := l.svc.GetPersonByMemberIdAndGroupId(l.ctx, personId, groupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 只有群主可以设置管理员
|
||||
if personId != group.GroupOwnerId || person.GroupMemberType != biz.GroupMemberTypeOwner || memberId == personId {
|
||||
err = xerror.NewError(xerror.GroupOwnerSetAdmin)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
member, err := l.svc.GetMemberByMemberIdAndGroupId(l.ctx, memberId, groupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = group.TrySetAdmin(); memberType == biz.GroupMemberTypeAdmin && err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = l.svc.SetAdmin(l.ctx, group, member, memberType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.SetAdminResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user