-
-
Notifications
You must be signed in to change notification settings - Fork 264
/
delete_user_logic.go
46 lines (38 loc) · 1.26 KB
/
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
package user
import (
"context"
"github.com/suyuan32/simple-admin-core/pkg/ent"
"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 DeleteUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic {
return &DeleteUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DeleteUserLogic) DeleteUser(in *core.UUIDReq) (*core.BaseResp, error) {
err := l.svcCtx.DB.User.DeleteOneID(uuidx.ParseUUIDString(in.Id)).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
}