update
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user