Files
breakpilot-lehrer/school-service/internal/handlers/handlers.go
T
Benjamin Admin e958f88a2d Add timetable scheduler Phases 1 + 2 to school-service
Phase 1 — Stammdaten (7 tables):
  tt_class, tt_period, tt_room, tt_subject, tt_teacher,
  tt_curriculum, tt_assignment with CRUD endpoints.

Phase 2 — Constraints (15 typed tables):
  Teacher (6): unavailable_day, unavailable_window, max_hours_day,
    max_hours_week, excluded_subject, excluded_room
  Subject (5): min_day_gap, max_consecutive, contiguous_when_repeated,
    preferred_period, double_lesson
  Class (2): max_hours_day, no_gaps
  Room (2): requires_type, unavailable

Each constraint row carries is_hard / weight / active / note /
created_by_user_id; ownership enforced via WHERE EXISTS against the
parent tt_teacher/tt_class/tt_subject/tt_room row.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 22:12:23 +02:00

70 lines
2.1 KiB
Go

package handlers
import (
"net/http"
"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
}
// NewHandler creates a new Handler with all services
func NewHandler(db *pgxpool.Pool, llmGatewayURL 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)
return &Handler{
classService: classService,
examService: examService,
gradeService: gradeService,
gradebookService: gradebookService,
certificateService: certificateService,
aiService: aiService,
timetableService: timetableService,
}
}
// 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)
}