update
This commit is contained in:
@@ -15,21 +15,21 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
roleService v1.RoleService
|
||||
menuService v1.MenuService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, roleService v1.RoleService, menuService v1.MenuService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, roleService v1.RoleService, menuService v1.MenuService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
roleService: roleService,
|
||||
menuService: menuService,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) list(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) list(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
ctx := r.Context()
|
||||
@@ -61,12 +61,12 @@ func (a *App) list(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) add(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) add(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
a.render.Render(ctx, w, role.Edit(ctx, &system.Role{Sort: 6666}))
|
||||
}
|
||||
|
||||
func (a *App) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
vars := r.URL.Query()
|
||||
parentID := convertor.QueryInt[int32](vars, "parentID", 0)
|
||||
vm := &system.Role{ParentID: parentID, Sort: 6666}
|
||||
@@ -74,7 +74,7 @@ func (a *App) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, role.Edit(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) edit(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
vars := r.URL.Query()
|
||||
id := convertor.QueryInt[int32](vars, "id", 0)
|
||||
@@ -85,7 +85,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, role.Edit(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) save(w http.ResponseWriter, r *http.Request) {
|
||||
var req form.Role
|
||||
if err := binding.Form.Bind(r, &req); err != nil {
|
||||
a.render.JSONErr(w, binding.ValidatorErrors(err))
|
||||
@@ -110,7 +110,7 @@ func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) data(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) data(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
vars := r.URL.Query()
|
||||
t := vars.Get("type")
|
||||
@@ -131,7 +131,7 @@ func (a *App) data(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
err := a.roleService.RefreshCache(r.Context())
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, err.Error())
|
||||
@@ -141,7 +141,7 @@ func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "缓存刷新成功")
|
||||
}
|
||||
|
||||
func (a *App) rebuildParentPath(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) rebuildParentPath(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
err := a.roleService.RebuildParentPath(ctx)
|
||||
if err != nil {
|
||||
@@ -152,7 +152,7 @@ func (a *App) rebuildParentPath(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "重建成功")
|
||||
}
|
||||
|
||||
func (a *App) refreshRoleMenus(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) refreshRoleMenus(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
// 获取需要刷新的角色ID
|
||||
@@ -191,7 +191,7 @@ func (a *App) refreshRoleMenus(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "刷新成功")
|
||||
}
|
||||
|
||||
func (a *App) setMenu(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) setMenu(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
vars := r.URL.Query()
|
||||
|
||||
@@ -19,7 +19,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.RoleService, cfg.MenuService)
|
||||
app := newApp(cfg.Render, cfg.RoleService, cfg.MenuService)
|
||||
|
||||
r.Route("/role", func(r chi.Router) {
|
||||
r.Use(mid.Audit(cfg.Sm, cfg.Log))
|
||||
|
||||
Reference in New Issue
Block a user