-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
batch_delete_user_logic.go
47 lines (39 loc) · 1.37 KB
/
batch_delete_user_logic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package user
import (
"context"
"github.com/suyuan32/simple-admin-core/pkg/ent"
"github.com/suyuan32/simple-admin-core/pkg/ent/user"
"github.com/suyuan32/simple-admin-core/pkg/i18n"
"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
"github.com/suyuan32/simple-admin-core/pkg/statuserr"
"github.com/suyuan32/simple-admin-core/pkg/uuidx"
"github.com/suyuan32/simple-admin-core/rpc/internal/svc"
"github.com/suyuan32/simple-admin-core/rpc/types/core"
"github.com/zeromicro/go-zero/core/logx"
)
type BatchDeleteUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewBatchDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BatchDeleteUserLogic {
return &BatchDeleteUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *BatchDeleteUserLogic) BatchDeleteUser(in *core.UUIDsReq) (*core.BaseResp, error) {
_, err := l.svcCtx.DB.User.Delete().Where(user.IDIn(uuidx.ParseUUIDSlice(in.Ids)...)).Exec(l.ctx)
if err != nil {
switch {
case ent.IsNotFound(err):
logx.Errorw(err.Error(), logx.Field("detail", in))
return nil, statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
default:
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
return nil, statuserr.NewInternalError(i18n.DatabaseError)
}
}
return &core.BaseResp{Msg: i18n.DeleteSuccess}, nil
}