update
This commit is contained in:
@@ -8,14 +8,14 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
config *config.Config
|
||||
render render.Renderer
|
||||
captchaService v1.CaptchaService
|
||||
}
|
||||
|
||||
func NewApp(config *config.Config, render render.Renderer, captchaService v1.CaptchaService) *App {
|
||||
return &App{
|
||||
func newApp(config *config.Config, render render.Renderer, captchaService v1.CaptchaService) *app {
|
||||
return &app{
|
||||
config: config,
|
||||
render: render,
|
||||
captchaService: captchaService,
|
||||
@@ -29,7 +29,7 @@ type Response struct {
|
||||
OpenCaptcha int `json:"open_captcha"`
|
||||
}
|
||||
|
||||
func (a *App) captcha(w http.ResponseWriter, _ *http.Request) {
|
||||
func (a *app) captcha(w http.ResponseWriter, _ *http.Request) {
|
||||
id, b64s, _, err := a.captchaService.Generate(
|
||||
a.config.Captcha.ImgHeight,
|
||||
a.config.Captcha.ImgWidth,
|
||||
|
||||
@@ -15,6 +15,6 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Conf, cfg.Render, cfg.CaptchaService)
|
||||
app := newApp(cfg.Conf, cfg.Render, cfg.CaptchaService)
|
||||
r.Get("/captcha", app.captcha)
|
||||
}
|
||||
|
||||
@@ -10,19 +10,19 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
auditLogService v1.AuditLogService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, auditLogService v1.AuditLogService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, auditLogService v1.AuditLogService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
auditLogService: auditLogService,
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@@ -16,7 +16,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.AuditLogService)
|
||||
app := newApp(cfg.Render, cfg.AuditLogService)
|
||||
|
||||
r.Route("/audit_log", func(r chi.Router) {
|
||||
r.Get("/list", app.list)
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/drhin/logger"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
log *logger.Logger
|
||||
sm session.Manager
|
||||
render render.Renderer
|
||||
@@ -24,14 +24,14 @@ type App struct {
|
||||
userService v1.UserService
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
func newApp(
|
||||
log *logger.Logger,
|
||||
sm session.Manager,
|
||||
render render.Renderer,
|
||||
captchaService v1.CaptchaService,
|
||||
userService v1.UserService,
|
||||
) *App {
|
||||
return &App{
|
||||
) *app {
|
||||
return &app{
|
||||
log: log,
|
||||
sm: sm,
|
||||
render: render,
|
||||
@@ -40,7 +40,7 @@ func NewApp(
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) login(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) login(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
@@ -88,7 +88,7 @@ func (a *App) login(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) logout(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) logout(w http.ResponseWriter, r *http.Request) {
|
||||
err := a.sm.Destroy(r.Context())
|
||||
if err != nil {
|
||||
a.log.Error(err.Error(), err)
|
||||
|
||||
@@ -20,7 +20,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Log, cfg.Sm, cfg.Render, cfg.CaptchaService, cfg.UserService)
|
||||
app := newApp(cfg.Log, cfg.Sm, cfg.Render, cfg.CaptchaService, cfg.UserService)
|
||||
|
||||
r.Get("/", app.login)
|
||||
r.Post("/login", app.login)
|
||||
|
||||
@@ -15,19 +15,19 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
configService systemService.ConfigService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, configService systemService.ConfigService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, configService systemService.ConfigService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
configService: configService,
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -57,12 +57,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, config.Edit(ctx, &view.EditSysConfig{Config: &systemModel.Config{}}))
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -77,7 +77,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, config.Edit(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) save(w http.ResponseWriter, r *http.Request) {
|
||||
id := convertor.ConvertInt[int32](r.PostFormValue("ID"), 0)
|
||||
key := r.PostFormValue("Key")
|
||||
value := r.PostFormValue("Value")
|
||||
@@ -125,7 +125,7 @@ func (a *App) save(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) {
|
||||
key := r.FormValue("key")
|
||||
err := a.configService.RefreshCache(r.Context(), strings.ToLower(key))
|
||||
if err != nil {
|
||||
@@ -136,7 +136,7 @@ func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "刷新成功")
|
||||
}
|
||||
|
||||
func (a *App) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
err := a.configService.ResetPear(r.Context())
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, err.Error())
|
||||
@@ -145,7 +145,7 @@ func (a *App) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "重置成功")
|
||||
}
|
||||
|
||||
func (a *App) pear(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) pear(w http.ResponseWriter, r *http.Request) {
|
||||
pear, err := a.configService.Pear(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -19,7 +19,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.ConfigService)
|
||||
app := newApp(cfg.Render, cfg.ConfigService)
|
||||
|
||||
r.Get("/pear.json", app.pear)
|
||||
r.Route("/config", func(r chi.Router) {
|
||||
|
||||
@@ -13,19 +13,19 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
departmentService v1.DepartmentService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, departmentService v1.DepartmentService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, departmentService v1.DepartmentService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
departmentService: departmentService,
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -57,12 +57,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, department.Edit(ctx, &systemmodel.Department{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 := &systemmodel.Department{ParentID: parentID, Sort: 6666}
|
||||
@@ -70,7 +70,7 @@ func (a *App) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, department.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)
|
||||
@@ -81,7 +81,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, department.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.Department
|
||||
if err := binding.Form.Bind(r, &req); err != nil {
|
||||
a.render.JSONErr(w, binding.ValidatorErrors(err))
|
||||
@@ -107,7 +107,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")
|
||||
@@ -130,7 +130,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.departmentService.RefreshCache(r.Context())
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, err.Error())
|
||||
@@ -140,7 +140,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.departmentService.RebuildParentPath(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,7 +19,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.DepartmentService)
|
||||
app := newApp(cfg.Render, cfg.DepartmentService)
|
||||
|
||||
r.Route("/department", func(r chi.Router) {
|
||||
r.Use(mid.Audit(cfg.Sm, cfg.Log))
|
||||
|
||||
@@ -9,20 +9,20 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
userService v1.UserService
|
||||
menuService v1.MenuService
|
||||
loginLogService v1.LoginLogService
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
func newApp(
|
||||
render render.Renderer,
|
||||
userService v1.UserService,
|
||||
menuService v1.MenuService,
|
||||
loginLogService v1.LoginLogService,
|
||||
) *App {
|
||||
return &App{
|
||||
) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
userService: userService,
|
||||
menuService: menuService,
|
||||
@@ -30,12 +30,12 @@ func NewApp(
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) home(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) home(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
a.render.Render(ctx, w, home.Home(ctx))
|
||||
}
|
||||
|
||||
func (a *App) dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
auth := mid.GetUser(ctx)
|
||||
lt, _ := a.loginLogService.LoginTime(ctx, auth.Email)
|
||||
|
||||
@@ -18,7 +18,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.UserService, cfg.MenuService, cfg.LoginLogService)
|
||||
app := newApp(cfg.Render, cfg.UserService, cfg.MenuService, cfg.LoginLogService)
|
||||
|
||||
r.With(mid.Authorize(cfg.Sm, cfg.MenuService)).Get("/home.html", app.home)
|
||||
r.With(mid.Authorize(cfg.Sm, cfg.MenuService)).Get("/dashboard", app.dashboard)
|
||||
|
||||
@@ -10,19 +10,19 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
loginLogService v1.LoginLogService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, loginLogService v1.LoginLogService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, loginLogService v1.LoginLogService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
loginLogService: loginLogService,
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@@ -16,7 +16,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.LoginLogService)
|
||||
app := newApp(cfg.Render, cfg.LoginLogService)
|
||||
|
||||
r.Route("/login_log", func(r chi.Router) {
|
||||
r.Get("/list", app.list)
|
||||
|
||||
@@ -19,19 +19,19 @@ import (
|
||||
|
||||
const style = "layui-btn-primary layui-btn-sm"
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
menuService v1.MenuService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, menuService v1.MenuService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, menuService v1.MenuService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
menuService: menuService,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) menus(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) menus(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
user := mid.GetUser(ctx)
|
||||
menus, err := a.menuService.OwerMenus(ctx, user.RoleID)
|
||||
@@ -43,7 +43,7 @@ func (a *App) menus(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSON(w, menus)
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -67,12 +67,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, menu.Edit(ctx, &systemmodel.Menu{Style: style, Visible: true, Sort: 6666}))
|
||||
}
|
||||
|
||||
func (a *App) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
vars := r.URL.Query()
|
||||
parentID := convertor.QueryInt[int32](vars, "parentID", 0)
|
||||
@@ -88,7 +88,7 @@ func (a *App) addChildren(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, menu.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)
|
||||
@@ -99,7 +99,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, menu.Edit(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) save(w http.ResponseWriter, r *http.Request) {
|
||||
id := convertor.ConvertInt[int32](r.PostFormValue("ID"), 0)
|
||||
name := r.PostFormValue("Name")
|
||||
displayName := r.PostFormValue("DisplayName")
|
||||
@@ -190,7 +190,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")
|
||||
@@ -216,7 +216,7 @@ func (a *App) data(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSON(w, nil)
|
||||
}
|
||||
|
||||
func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
err := a.menuService.RefreshCache(r.Context())
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, err.Error())
|
||||
|
||||
@@ -18,7 +18,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.MenuService)
|
||||
app := newApp(cfg.Render, cfg.MenuService)
|
||||
|
||||
r.Get("/menus", app.menus)
|
||||
r.Route("/menu", func(r chi.Router) {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -21,7 +21,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(
|
||||
app := newApp(
|
||||
cfg.Log,
|
||||
cfg.Sm,
|
||||
cfg.Render,
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/drhin/logger"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
log *logger.Logger
|
||||
sm session.Manager
|
||||
render render.Renderer
|
||||
@@ -26,15 +26,15 @@ type App struct {
|
||||
departmentService v1.DepartmentService
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
func newApp(
|
||||
log *logger.Logger,
|
||||
sm session.Manager,
|
||||
render render.Renderer,
|
||||
userService v1.UserService,
|
||||
roleService v1.RoleService,
|
||||
departmentService v1.DepartmentService,
|
||||
) *App {
|
||||
return &App{
|
||||
) *app {
|
||||
return &app{
|
||||
log: log,
|
||||
sm: sm,
|
||||
render: render,
|
||||
@@ -44,12 +44,12 @@ func NewApp(
|
||||
}
|
||||
}
|
||||
|
||||
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, user.Edit(ctx, &systemmodel.User{HashedPassword: nil}))
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -63,7 +63,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, user.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.User
|
||||
if err := binding.Form.Bind(r, &req); err != nil {
|
||||
a.render.JSONErr(w, binding.ValidatorErrors(err))
|
||||
@@ -103,7 +103,7 @@ func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -135,14 +135,14 @@ func (a *App) list(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) profile(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) profile(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
u := mid.GetUser(ctx)
|
||||
vm, _ := a.userService.Get(ctx, u.ID)
|
||||
a.render.Render(ctx, w, user.Profile(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) data(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) data(w http.ResponseWriter, r *http.Request) {
|
||||
vars := r.URL.Query()
|
||||
t := vars.Get("type")
|
||||
if t == "xm_select" {
|
||||
|
||||
Reference in New Issue
Block a user