44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
|
|
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)
|
||
|
|
}
|