package api import ( "net/http" "github.com/gin-gonic/gin" "github.com/simpletodoapp/go-todo-app/internal/database" "github.com/simpletodoapp/go-todo-app/internal/dto" ) // HealthHandler handles health check requests type HealthHandler struct { db *database.Database } // NewHealthHandler creates a new health check handler func NewHealthHandler(db *database.Database) *HealthHandler { return &HealthHandler{db: db} } // RegisterRoutes registers the health check routes func (h *HealthHandler) RegisterRoutes(router *gin.Engine) { router.GET("/health", h.HealthCheck) } // HealthCheck handles GET /health // Returns the health status of the application func (h *HealthHandler) HealthCheck(c *gin.Context) { // Check database health dbStatus := "healthy" if err := h.db.Health(); err != nil { dbStatus = "unhealthy" } response := dto.HealthResponse{ Status: "healthy", DBStatus: dbStatus, } c.JSON(http.StatusOK, response) }