package handlers import ( "net/http" "github.com/breakpilot/school-service/internal/notifications" "github.com/breakpilot/school-service/internal/services" "github.com/gin-gonic/gin" "github.com/jackc/pgx/v5/pgxpool" ) // Handler holds all the service dependencies type Handler struct { classService *services.ClassService examService *services.ExamService gradeService *services.GradeService gradebookService *services.GradebookService certificateService *services.CertificateService aiService *services.AIService timetableService *services.TimetableService calendarService *services.CalendarService parentService *services.ParentService notificationService *notifications.Service solverServiceURL string } // NewHandler creates a new Handler with all services func NewHandler(db *pgxpool.Pool, llmGatewayURL, solverServiceURL, matrixURL, emailURL string) *Handler { classService := services.NewClassService(db) examService := services.NewExamService(db) gradeService := services.NewGradeService(db) gradebookService := services.NewGradebookService(db) certificateService := services.NewCertificateService(db, gradeService, gradebookService) aiService := services.NewAIService(llmGatewayURL) timetableService := services.NewTimetableService(db) calendarService := services.NewCalendarService(db) parentService := services.NewParentService(db) notificationService := notifications.NewService(db, matrixURL, emailURL) return &Handler{ classService: classService, examService: examService, gradeService: gradeService, gradebookService: gradebookService, certificateService: certificateService, aiService: aiService, timetableService: timetableService, calendarService: calendarService, parentService: parentService, notificationService: notificationService, solverServiceURL: solverServiceURL, } } // NotificationService exposes the underlying service so main.go can run // the daily cron tick. func (h *Handler) NotificationService() *notifications.Service { return h.notificationService } // CalendarService exposes the underlying service so main.go can run the // one-off seed import after migrations. func (h *Handler) CalendarService() *services.CalendarService { return h.calendarService } // ParentService exposes the parent service so the parent-session middleware // in main.go can resolve session cookies. func (h *Handler) ParentService() *services.ParentService { return h.parentService } // Health returns the service health status func (h *Handler) Health(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "status": "healthy", "service": "school-service", }) } // getUserID extracts the user ID from the context (set by auth middleware) func getUserID(c *gin.Context) string { return c.GetString("user_id") } // respondError sends an error response func respondError(c *gin.Context, status int, message string) { c.JSON(status, gin.H{"error": message}) } // respondSuccess sends a success response with data func respondSuccess(c *gin.Context, data interface{}) { c.JSON(http.StatusOK, data) } // respondCreated sends a created response with data func respondCreated(c *gin.Context, data interface{}) { c.JSON(http.StatusCreated, data) }