2025-05-07 14:12:53 +08:00

45 lines
1.0 KiB
Go

package system
import (
"net/http"
"management/internal/erpserver/handler"
v1 "management/internal/erpserver/service/v1"
)
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) {
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)
t := h.loginLogService.LoginLatestTime(ctx, auth.Email)
c := h.loginLogService.LoginCount(ctx, auth.Email)
h.HTML(w, r, "home/dashboard.tmpl", map[string]any{
"Auth": auth,
"User": user,
"LastLoginTime": t,
"LoginCount": c,
})
}