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