Files
Novault-backend/internal/handler/health_score_handler.go

44 lines
1.1 KiB
Go
Raw Permalink Normal View History

2026-01-27 18:42:35 +08:00
package handler
import (
"accounting-app/internal/service"
"accounting-app/pkg/api"
"github.com/gin-gonic/gin"
)
// HealthScoreHandler handles HTTP requests for health score
type HealthScoreHandler struct {
healthScoreService *service.HealthScoreService
}
// NewHealthScoreHandler creates a new HealthScoreHandler instance
func NewHealthScoreHandler(healthScoreService *service.HealthScoreService) *HealthScoreHandler {
return &HealthScoreHandler{
healthScoreService: healthScoreService,
}
}
// GetHealthScore handles GET /api/v1/reports/health-score
// Returns the user's financial health score
func (h *HealthScoreHandler) GetHealthScore(c *gin.Context) {
userID, exists := c.Get("user_id")
if !exists {
api.Unauthorized(c, "User not authenticated")
return
}
result, err := h.healthScoreService.CalculateHealthScore(userID.(uint))
if err != nil {
api.InternalError(c, "Failed to calculate health score: "+err.Error())
return
}
api.Success(c, result)
}
// RegisterRoutes registers health score route
func (h *HealthScoreHandler) RegisterRoutes(rg *gin.RouterGroup) {
rg.GET("/reports/health-score", h.GetHealthScore)
}