This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BreakPilot Dev 19855efacc
Some checks failed
Tests / Go Tests (push) Has been cancelled
Tests / Python Tests (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / Go Lint (push) Has been cancelled
Tests / Python Lint (push) Has been cancelled
Tests / Security Scan (push) Has been cancelled
Tests / All Checks Passed (push) Has been cancelled
Security Scanning / Secret Scanning (push) Has been cancelled
Security Scanning / Dependency Vulnerability Scan (push) Has been cancelled
Security Scanning / Go Security Scan (push) Has been cancelled
Security Scanning / Python Security Scan (push) Has been cancelled
Security Scanning / Node.js Security Scan (push) Has been cancelled
Security Scanning / Docker Image Security (push) Has been cancelled
Security Scanning / Security Summary (push) Has been cancelled
CI/CD Pipeline / Go Tests (push) Has been cancelled
CI/CD Pipeline / Python Tests (push) Has been cancelled
CI/CD Pipeline / Website Tests (push) Has been cancelled
CI/CD Pipeline / Linting (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Docker Build & Push (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / CI Summary (push) Has been cancelled
ci/woodpecker/manual/build-ci-image Pipeline was successful
ci/woodpecker/manual/main Pipeline failed
feat: BreakPilot PWA - Full codebase (clean push without large binaries)
All services: admin-v2, studio-v2, website, ai-compliance-sdk,
consent-service, klausur-service, voice-service, and infrastructure.
Large PDFs and compiled binaries excluded via .gitignore.
2026-02-11 13:25:58 +01:00

243 lines
6.3 KiB
Go

package handlers
import (
"net/http"
"github.com/breakpilot/school-service/internal/models"
"github.com/gin-gonic/gin"
)
// School Year Handlers
// CreateSchoolYear creates a new school year
func (h *Handler) CreateSchoolYear(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
var req models.CreateSchoolYearRequest
if err := c.ShouldBindJSON(&req); err != nil {
respondError(c, http.StatusBadRequest, "Invalid request: "+err.Error())
return
}
year, err := h.classService.CreateSchoolYear(c.Request.Context(), teacherID, &req)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to create school year: "+err.Error())
return
}
respondCreated(c, year)
}
// GetSchoolYears returns all school years for the current teacher
func (h *Handler) GetSchoolYears(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
years, err := h.classService.GetSchoolYears(c.Request.Context(), teacherID)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to get school years: "+err.Error())
return
}
respondSuccess(c, years)
}
// Class Handlers
// CreateClass creates a new class
func (h *Handler) CreateClass(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
var req models.CreateClassRequest
if err := c.ShouldBindJSON(&req); err != nil {
respondError(c, http.StatusBadRequest, "Invalid request: "+err.Error())
return
}
class, err := h.classService.CreateClass(c.Request.Context(), teacherID, &req)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to create class: "+err.Error())
return
}
respondCreated(c, class)
}
// GetClasses returns all classes for the current teacher
func (h *Handler) GetClasses(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
classes, err := h.classService.GetClasses(c.Request.Context(), teacherID)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to get classes: "+err.Error())
return
}
respondSuccess(c, classes)
}
// GetClass returns a single class
func (h *Handler) GetClass(c *gin.Context) {
teacherID := getUserID(c)
classID := c.Param("id")
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
class, err := h.classService.GetClass(c.Request.Context(), classID, teacherID)
if err != nil {
respondError(c, http.StatusNotFound, "Class not found")
return
}
respondSuccess(c, class)
}
// DeleteClass deletes a class
func (h *Handler) DeleteClass(c *gin.Context) {
teacherID := getUserID(c)
classID := c.Param("id")
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
if err := h.classService.DeleteClass(c.Request.Context(), classID, teacherID); err != nil {
respondError(c, http.StatusInternalServerError, "Failed to delete class: "+err.Error())
return
}
c.JSON(http.StatusOK, gin.H{"message": "Class deleted"})
}
// Student Handlers
// CreateStudent creates a new student in a class
func (h *Handler) CreateStudent(c *gin.Context) {
classID := c.Param("id")
var req models.CreateStudentRequest
if err := c.ShouldBindJSON(&req); err != nil {
respondError(c, http.StatusBadRequest, "Invalid request: "+err.Error())
return
}
student, err := h.classService.CreateStudent(c.Request.Context(), classID, &req)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to create student: "+err.Error())
return
}
respondCreated(c, student)
}
// GetStudents returns all students in a class
func (h *Handler) GetStudents(c *gin.Context) {
classID := c.Param("id")
students, err := h.classService.GetStudents(c.Request.Context(), classID)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to get students: "+err.Error())
return
}
respondSuccess(c, students)
}
// DeleteStudent deletes a student
func (h *Handler) DeleteStudent(c *gin.Context) {
studentID := c.Param("studentId")
if err := h.classService.DeleteStudent(c.Request.Context(), studentID); err != nil {
respondError(c, http.StatusInternalServerError, "Failed to delete student: "+err.Error())
return
}
c.JSON(http.StatusOK, gin.H{"message": "Student deleted"})
}
// ImportStudents imports students from CSV (placeholder)
func (h *Handler) ImportStudents(c *gin.Context) {
// TODO: Implement CSV import
// For now, return a not implemented response
respondError(c, http.StatusNotImplemented, "CSV import not yet implemented")
}
// Subject Handlers
// CreateSubject creates a new subject
func (h *Handler) CreateSubject(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
var req models.CreateSubjectRequest
if err := c.ShouldBindJSON(&req); err != nil {
respondError(c, http.StatusBadRequest, "Invalid request: "+err.Error())
return
}
subject, err := h.classService.CreateSubject(c.Request.Context(), teacherID, &req)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to create subject: "+err.Error())
return
}
respondCreated(c, subject)
}
// GetSubjects returns all subjects for the current teacher
func (h *Handler) GetSubjects(c *gin.Context) {
teacherID := getUserID(c)
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
subjects, err := h.classService.GetSubjects(c.Request.Context(), teacherID)
if err != nil {
respondError(c, http.StatusInternalServerError, "Failed to get subjects: "+err.Error())
return
}
respondSuccess(c, subjects)
}
// DeleteSubject deletes a subject
func (h *Handler) DeleteSubject(c *gin.Context) {
teacherID := getUserID(c)
subjectID := c.Param("id")
if teacherID == "" {
respondError(c, http.StatusUnauthorized, "User not authenticated")
return
}
if err := h.classService.DeleteSubject(c.Request.Context(), subjectID, teacherID); err != nil {
respondError(c, http.StatusInternalServerError, "Failed to delete subject: "+err.Error())
return
}
c.JSON(http.StatusOK, gin.H{"message": "Subject deleted"})
}