2025-06-13 17:23:16 +08:00

49 lines
1.2 KiB
Go

package system
import (
"net/http"
"management/internal/erpserver/handler"
v1 "management/internal/erpserver/service/v1"
"management/internal/erpserver/templ/home"
)
type HomeHandler struct {
*handler.Handler
userService v1.UserService
loginLogService v1.LoginLogService
}
func NewHomeHandler(
handler *handler.Handler,
userService v1.UserService,
loginLogService v1.LoginLogService,
) *HomeHandler {
return &HomeHandler{
Handler: handler,
userService: userService,
loginLogService: loginLogService,
}
}
func (h *HomeHandler) Home(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
h.Render(ctx, w, home.Home(ctx))
//h.HTML(w, r, "home/home.tmpl", nil)
}
func (h *HomeHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
auth := h.AuthUser(ctx)
//user, _ := h.userService.Get(ctx, auth.ID)
lt, _ := h.loginLogService.LoginTime(ctx, auth.Email)
c := h.loginLogService.LoginCount(ctx, auth.Email)
h.Render(ctx, w, home.Dashboard(ctx, int(c), lt.ThisLoginTime, lt.LastLoginTime))
//h.HTML(w, r, "home/dashboard.tmpl", map[string]any{
// "Auth": auth,
// "User": user,
// "LoginTime": lt,
// "LoginCount": c,
//})
}