change router struct
This commit is contained in:
44
internal/erpserver/handler/system/home/home.go
Normal file
44
internal/erpserver/handler/system/home/home.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
v1 "management/internal/erpserver/service/v1"
|
||||
"management/internal/erpserver/templ/home"
|
||||
"management/internal/pkg/mid"
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
render render.Renderer
|
||||
userService v1.UserService
|
||||
menuService v1.MenuService
|
||||
loginLogService v1.LoginLogService
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
render render.Renderer,
|
||||
userService v1.UserService,
|
||||
menuService v1.MenuService,
|
||||
loginLogService v1.LoginLogService,
|
||||
) *App {
|
||||
return &App{
|
||||
render: render,
|
||||
userService: userService,
|
||||
menuService: menuService,
|
||||
loginLogService: loginLogService,
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
ctx := r.Context()
|
||||
auth := mid.GetUser(ctx)
|
||||
lt, _ := a.loginLogService.LoginTime(ctx, auth.Email)
|
||||
c := a.loginLogService.LoginCount(ctx, auth.Email)
|
||||
a.render.Render(ctx, w, home.Dashboard(ctx, int(c), lt.ThisLoginTime, lt.LastLoginTime))
|
||||
}
|
||||
25
internal/erpserver/handler/system/home/route.go
Normal file
25
internal/erpserver/handler/system/home/route.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
v1 "management/internal/erpserver/service/v1"
|
||||
"management/internal/pkg/mid"
|
||||
"management/internal/pkg/render"
|
||||
"management/internal/pkg/session"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Sm session.Manager
|
||||
Render render.Renderer
|
||||
UserService v1.UserService
|
||||
MenuService v1.MenuService
|
||||
LoginLogService v1.LoginLogService
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user