97e37837ee
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 29s
CI / test-go-edu-search (push) Successful in 27s
CI / test-python-klausur (push) Failing after 2m50s
CI / test-python-agent-core (push) Successful in 18s
CI / test-nodejs-website (push) Successful in 21s
Backend (school-service):
- cal_public_event (region, event_type, name_de, name_en, start/end,
UNIQUE(region, event_type, name_de, start_date)) — global snapshot.
- cal_school_config (user_id PRIMARY KEY, bundesland, school year dates).
- cal_school_event — Schul-eigene Termine; CRUD folgt in 9b.
- GET /calendar/holidays?region=&from=&to= — Range-Query against
cal_public_event, ordered by start_date.
- GET / PUT /calendar/config — upsert Bundesland per User.
- SeedFromSnapshot reads internal/seed/calendar_holidays.json on every
boot; idempotent via the unique constraint. Async goroutine so the
HTTP server starts immediately even if the seed file is large.
Data source:
- scripts/calendar-snapshot.sh ruft openholidaysapi.org fuer alle 16
Bundeslaender x 3 Schuljahre und schreibt
school-service/internal/seed/calendar_holidays.json (854 Events,
Stand Schuljahre 2026-2028).
- Dockerfile kopiert das seed/-Verzeichnis ins Image, damit die
Container-Datenbank beim ersten Start gefuellt wird.
Frontend (studio-v2):
- /schulkalender Page mit Gradient + Blobs wie /stundenplan und
/korrektur — gleicher Visual-Style.
- BundeslandWizard: zeigt alle 16 Laender als Dropdown, speichert
bei Klick die Config und switcht zur Monatsansicht.
- MonthView: 6-Wochen-Grid Mo-So, Feiertage rose-toned, Schulferien
amber-toned, heutiges Datum mit Indigo-Ring. Prev/Next/Heute
Navigation.
- lib/schulkalender/api.ts re-uses the stundenplan JWT helper so
auth-mode wechselt nicht.
- Sidebar bekommt einen Schulkalender-Eintrag (Icon mit Datum-Dots,
Pfad /schulkalender) in allen 26 Sprachen.
Tests:
- Go: 3 neue Validator-Tests (Bundesland len=5, EventType oneof,
Pflichtfelder). 77 Tests gesamt, alle gruen.
- Playwright: e2e/schulkalender.spec.ts mit Wizard, Save-Flow,
MonthView-Render, Heute-Button, Sidebar-Link. Hermetisch via
mockCalendarApi.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/breakpilot/school-service/internal/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ListCalendarHolidays returns OpenHolidaysAPI events for a region + range.
|
|
// Query params: ?region=DE-NI&from=2026-08-01&to=2027-07-31. If omitted,
|
|
// region falls back to the caller's saved config and the range to the
|
|
// current calendar year.
|
|
func (h *Handler) ListCalendarHolidays(c *gin.Context) {
|
|
uid := getUserID(c)
|
|
if uid == "" {
|
|
respondError(c, http.StatusUnauthorized, "User not authenticated")
|
|
return
|
|
}
|
|
region := c.Query("region")
|
|
if region == "" {
|
|
cfg, err := h.calendarService.GetConfig(c.Request.Context(), uid)
|
|
if err != nil || cfg == nil {
|
|
respondError(c, http.StatusBadRequest, "region query param required (no saved config)")
|
|
return
|
|
}
|
|
region = cfg.Bundesland
|
|
}
|
|
from := c.DefaultQuery("from", time.Now().Format("2006-01-02"))
|
|
to := c.DefaultQuery("to", time.Now().AddDate(1, 0, 0).Format("2006-01-02"))
|
|
|
|
events, err := h.calendarService.ListHolidays(c.Request.Context(), region, from, to)
|
|
if err != nil {
|
|
respondError(c, http.StatusInternalServerError, "Failed to load holidays: "+err.Error())
|
|
return
|
|
}
|
|
if events == nil {
|
|
events = []models.PublicEvent{}
|
|
}
|
|
respondSuccess(c, events)
|
|
}
|
|
|
|
func (h *Handler) GetCalendarConfig(c *gin.Context) {
|
|
uid := getUserID(c)
|
|
if uid == "" {
|
|
respondError(c, http.StatusUnauthorized, "User not authenticated")
|
|
return
|
|
}
|
|
cfg, err := h.calendarService.GetConfig(c.Request.Context(), uid)
|
|
if err != nil {
|
|
// No row → 200 with null so the wizard knows to prompt.
|
|
respondSuccess(c, nil)
|
|
return
|
|
}
|
|
respondSuccess(c, cfg)
|
|
}
|
|
|
|
func (h *Handler) UpsertCalendarConfig(c *gin.Context) {
|
|
uid := getUserID(c)
|
|
if uid == "" {
|
|
respondError(c, http.StatusUnauthorized, "User not authenticated")
|
|
return
|
|
}
|
|
var req models.UpsertSchoolCalendarConfigRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
respondError(c, http.StatusBadRequest, "Invalid request: "+err.Error())
|
|
return
|
|
}
|
|
cfg, err := h.calendarService.UpsertConfig(c.Request.Context(), uid, &req)
|
|
if err != nil {
|
|
respondError(c, http.StatusInternalServerError, "Failed to save config: "+err.Error())
|
|
return
|
|
}
|
|
respondCreated(c, cfg)
|
|
}
|