优化结构
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"kra/internal/service"
|
||||
"errors"
|
||||
"kra/internal/biz/system"
|
||||
"kra/internal/service/dto"
|
||||
systemservice "kra/internal/service/system"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -10,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
service *service.UserService
|
||||
auth *service.AuthService
|
||||
service *systemservice.UserService
|
||||
auth *systemservice.AuthService
|
||||
}
|
||||
|
||||
func NewUser(user *service.UserService, auth *service.AuthService) *User {
|
||||
func NewUser(user *systemservice.UserService, auth *systemservice.AuthService) *User {
|
||||
return &User{service: user, auth: auth}
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ func (h *User) Create(c *gin.Context) {
|
||||
}
|
||||
result, err := h.service.CreateUserRequest(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
if service.IsPasswordPolicyError(err) {
|
||||
if systemservice.IsPasswordPolicyError(err) {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -141,7 +143,7 @@ func (h *User) ResetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.ResetPassword(c.Request.Context(), req.ID, req.Password); err != nil {
|
||||
if service.IsPasswordPolicyError(err) {
|
||||
if systemservice.IsPasswordPolicyError(err) {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -171,7 +173,7 @@ func (h *User) ChangePassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.ChangePassword(c.Request.Context(), claims.ID, req.Password, req.NewPassword); err != nil {
|
||||
if service.IsPasswordPolicyError(err) {
|
||||
if systemservice.IsPasswordPolicyError(err) {
|
||||
Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -206,7 +208,11 @@ func (h *User) SetAuthorities(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.SetUserAuthorities(c.Request.Context(), req.ID, req.AuthorityIDs); err != nil {
|
||||
Fail(c, "修改失败")
|
||||
if errors.Is(err, system.ErrAuthoritiesRequired) {
|
||||
Fail(c, err.Error())
|
||||
} else {
|
||||
Fail(c, "修改失败")
|
||||
}
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "修改成功")
|
||||
|
||||
Reference in New Issue
Block a user