feat: rbac迁移完成,并已部署至dev服务器
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
menu "sundynix-micro-go/app/system/api/internal/handler/menu"
|
||||
operationRecord "sundynix-micro-go/app/system/api/internal/handler/operationRecord"
|
||||
role "sundynix-micro-go/app/system/api/internal/handler/role"
|
||||
user "sundynix-micro-go/app/system/api/internal/handler/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
@@ -27,7 +28,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除客户端
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/client/delete",
|
||||
Handler: client.DeleteClientHandler(serverCtx),
|
||||
},
|
||||
@@ -39,7 +40,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 更新客户端
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/client/update",
|
||||
Handler: client.UpdateClientHandler(serverCtx),
|
||||
},
|
||||
@@ -58,7 +59,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除字典
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/dict/delete",
|
||||
Handler: dict.DeleteDictHandler(serverCtx),
|
||||
},
|
||||
@@ -70,7 +71,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 更新字典
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/dict/update",
|
||||
Handler: dict.UpdateDictHandler(serverCtx),
|
||||
},
|
||||
@@ -95,7 +96,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除菜单
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/menu/delete",
|
||||
Handler: menu.DeleteMenuHandler(serverCtx),
|
||||
},
|
||||
@@ -107,7 +108,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 更新菜单
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/menu/update",
|
||||
Handler: menu.UpdateMenuHandler(serverCtx),
|
||||
},
|
||||
@@ -120,7 +121,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
[]rest.Route{
|
||||
{
|
||||
// 删除操作日志
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/log/delete",
|
||||
Handler: operationRecord.DeleteOperationRecordHandler(serverCtx),
|
||||
},
|
||||
@@ -145,7 +146,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 删除角色
|
||||
Method: http.MethodDelete,
|
||||
Method: http.MethodPost,
|
||||
Path: "/role/delete",
|
||||
Handler: role.DeleteRoleHandler(serverCtx),
|
||||
},
|
||||
@@ -157,7 +158,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
{
|
||||
// 更新角色
|
||||
Method: http.MethodPut,
|
||||
Method: http.MethodPost,
|
||||
Path: "/role/update",
|
||||
Handler: role.UpdateRoleHandler(serverCtx),
|
||||
},
|
||||
@@ -165,4 +166,41 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
// 创建用户
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/create",
|
||||
Handler: user.CreateUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 删除用户
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/delete",
|
||||
Handler: user.DeleteUserHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 用户列表
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/list",
|
||||
Handler: user.GetUserListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 重置密码
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/resetPassword",
|
||||
Handler: user.ResetPasswordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 更新用户
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/update",
|
||||
Handler: user.UpdateUserHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithPrefix("/api/sys"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserCreateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := user.NewCreateUserLogic(r.Context(), svcCtx)
|
||||
if err := l.CreateUser(&req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.IdsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := user.NewDeleteUserLogic(r.Context(), svcCtx)
|
||||
if err := l.DeleteUser(&req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := user.NewGetUserListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserList(&req)
|
||||
if err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.OkWithData(w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ResetPasswordReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||
if err := l.ResetPassword(&req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"sundynix-micro-go/app/system/api/internal/logic/user"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/common/response"
|
||||
)
|
||||
|
||||
func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UserUpdateReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
return
|
||||
}
|
||||
l := user.NewUpdateUserLogic(r.Context(), svcCtx)
|
||||
if err := l.UpdateUser(&req); err != nil {
|
||||
response.Fail(w, err.Error())
|
||||
} else {
|
||||
response.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
|
||||
return &CreateUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreateUserLogic) CreateUser(req *types.UserCreateReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.CreateUser(l.ctx, &system.CreateUserReq{
|
||||
Name: req.Name,
|
||||
Account: req.Account,
|
||||
Password: req.Password,
|
||||
Phone: req.Phone,
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic {
|
||||
return &DeleteUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteUserLogic) DeleteUser(req *types.IdsReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.DeleteUser(l.ctx, &system.DeleteUserReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
|
||||
return &GetUserListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetUserListLogic) GetUserList(req *types.UserListReq) (resp interface{}, err error) {
|
||||
rpcResp, err := l.svcCtx.SystemRpc.GetUserList(l.ctx, &system.GetUserListReq{
|
||||
Current: int32(req.Current),
|
||||
PageSize: int32(req.PageSize),
|
||||
Name: req.Name,
|
||||
Account: req.Account,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []map[string]interface{}
|
||||
for _, u := range rpcResp.List {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": u.Id,
|
||||
"name": u.Name,
|
||||
"account": u.Account,
|
||||
"nickName": u.NickName,
|
||||
"phone": u.Phone,
|
||||
"gender": u.Gender,
|
||||
"createdAt": u.CreatedAt,
|
||||
})
|
||||
}
|
||||
return map[string]interface{}{"list": list, "total": rpcResp.Total}, nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ResetPasswordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
|
||||
return &ResetPasswordLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.ResetPassword(l.ctx, &system.ResetPasswordReq{
|
||||
Id: req.Id,
|
||||
Password: req.Password,
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateUserLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
|
||||
return &UpdateUserLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateUserLogic) UpdateUser(req *types.UserUpdateReq) error {
|
||||
_, err := l.svcCtx.SystemRpc.UpdateUser(l.ctx, &system.UpdateUserReq{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Account: req.Account,
|
||||
Phone: req.Phone,
|
||||
NickName: req.NickName,
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
|
||||
@@ -98,6 +98,11 @@ type PageReq struct {
|
||||
Keyword string `json:"keyword,optional"`
|
||||
}
|
||||
|
||||
type ResetPasswordReq struct {
|
||||
Id string `json:"id"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type RoleListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
@@ -118,3 +123,28 @@ type RoleUpdateReq struct {
|
||||
Sort int `json:"sort,optional"`
|
||||
MenuIds []string `json:"menuIds,optional"`
|
||||
}
|
||||
|
||||
type UserCreateReq struct {
|
||||
Name string `json:"name"`
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
Phone string `json:"phone,optional"`
|
||||
NickName string `json:"nickName,optional"`
|
||||
RoleIds []string `json:"roleIds,optional"`
|
||||
}
|
||||
|
||||
type UserListReq struct {
|
||||
Current int `json:"current,optional"`
|
||||
PageSize int `json:"pageSize,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Account string `json:"account,optional"`
|
||||
}
|
||||
|
||||
type UserUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Account string `json:"account,optional"`
|
||||
Phone string `json:"phone,optional"`
|
||||
NickName string `json:"nickName,optional"`
|
||||
RoleIds []string `json:"roleIds,optional"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user