Add Stundenplan frontend scaffolding in studio-v2
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 31s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 2m36s
CI / test-python-agent-core (push) Successful in 20s
CI / test-nodejs-website (push) Successful in 22s

Phase 3 — initial UI for the timetable scheduler:
  - app/stundenplan/page.tsx with tab navigation (Klassen / Lehrer /
    Faecher / Raeume / Zeitraster / Stundentafel / Lehrauftraege /
    Regeln) and a dev-mode JWT entry to authenticate against
    school-service until full auth is wired up.
  - app/stundenplan/_components/KlassenManager.tsx as the working
    prototype for one entity (list / create / delete). Pattern can be
    copied for the other 6 stammdaten + 15 constraint editors.
  - lib/stundenplan/api.ts exposing typed clients for all 22 endpoints
    (7 stammdaten + 15 constraint tables). Constraints use a factory
    to keep the file tight.
  - app/api/school/[...path]/route.ts proxies the browser through
    Next.js to school-service so HTTPS studio-v2 can reach the plain
    HTTP backend.
  - Sidebar.tsx gains a Stundenplan entry with 26-language labels.
  - docker-compose.yml exposes SCHOOL_SERVICE_URL to studio-v2 and
    declares the school-service dependency.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-21 22:25:18 +02:00
parent 64e7176267
commit f21ecf293b
7 changed files with 757 additions and 0 deletions
+140
View File
@@ -0,0 +1,140 @@
/**
* Stundenplan API client. All requests go through /api/school/* which proxies
* to the school-service Gin server (port 8084). Auth token, if available, is
* passed via Authorization: Bearer; for now no token = upstream 401.
*/
import type {
TimetableClass, TimetablePeriod, TimetableRoom, TimetableSubject,
TimetableTeacher, TimetableCurriculum, TimetableAssignment,
CreateTimetableClass, CreateTimetablePeriod, CreateTimetableRoom,
CreateTimetableSubject, CreateTimetableTeacher,
CreateTimetableCurriculum, CreateTimetableAssignment,
TeacherUnavailableDay, TeacherUnavailableWindow, TeacherMaxHoursDay,
TeacherMaxHoursWeek, TeacherExcludedSubject, TeacherExcludedRoom,
SubjectMinDayGap, SubjectMaxConsecutive, SubjectContiguousWhenRepeated,
SubjectPreferredPeriod, SubjectDoubleLesson,
ClassMaxHoursDay, ClassNoGaps,
RoomRequiresType, RoomUnavailable,
} from '@/app/stundenplan/types'
const TOKEN_KEY = 'bp_stundenplan_jwt'
export function setStundenplanToken(token: string): void {
if (typeof window !== 'undefined') localStorage.setItem(TOKEN_KEY, token)
}
export function getStundenplanToken(): string {
if (typeof window === 'undefined') return ''
return localStorage.getItem(TOKEN_KEY) || ''
}
async function apiFetch<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(options.headers as Record<string, string> | undefined),
}
const token = getStundenplanToken()
if (token) headers['Authorization'] = `Bearer ${token}`
const res = await fetch(`/api/school${endpoint}`, { ...options, headers })
if (!res.ok) {
const errData = await res.json().catch(() => ({ error: 'Unknown error' }))
throw new Error(errData.error || errData.detail || `HTTP ${res.status}`)
}
if (res.status === 204) return undefined as T
return res.json()
}
// ---------- Stammdaten ----------
export const classesApi = {
list: () => apiFetch<TimetableClass[]>('/timetable/classes'),
create: (data: CreateTimetableClass) =>
apiFetch<TimetableClass>('/timetable/classes', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/classes/${id}`, { method: 'DELETE' }),
}
export const periodsApi = {
list: () => apiFetch<TimetablePeriod[]>('/timetable/periods'),
create: (data: CreateTimetablePeriod) =>
apiFetch<TimetablePeriod>('/timetable/periods', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/periods/${id}`, { method: 'DELETE' }),
}
export const roomsApi = {
list: () => apiFetch<TimetableRoom[]>('/timetable/rooms'),
create: (data: CreateTimetableRoom) =>
apiFetch<TimetableRoom>('/timetable/rooms', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/rooms/${id}`, { method: 'DELETE' }),
}
export const subjectsApi = {
list: () => apiFetch<TimetableSubject[]>('/timetable/subjects'),
create: (data: CreateTimetableSubject) =>
apiFetch<TimetableSubject>('/timetable/subjects', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/subjects/${id}`, { method: 'DELETE' }),
}
export const teachersApi = {
list: () => apiFetch<TimetableTeacher[]>('/timetable/teachers'),
create: (data: CreateTimetableTeacher) =>
apiFetch<TimetableTeacher>('/timetable/teachers', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/teachers/${id}`, { method: 'DELETE' }),
}
export const curriculumApi = {
list: () => apiFetch<TimetableCurriculum[]>('/timetable/curriculum'),
create: (data: CreateTimetableCurriculum) =>
apiFetch<TimetableCurriculum>('/timetable/curriculum', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/curriculum/${id}`, { method: 'DELETE' }),
}
export const assignmentsApi = {
list: () => apiFetch<TimetableAssignment[]>('/timetable/assignments'),
create: (data: CreateTimetableAssignment) =>
apiFetch<TimetableAssignment>('/timetable/assignments', { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/assignments/${id}`, { method: 'DELETE' }),
}
// ---------- Constraints ----------
/**
* Factory that builds a list/create/remove triple for a constraint endpoint.
* The 15 constraint tables share the same CRUD shape; only TItem differs.
*/
function constraintApi<TItem, TCreate>(path: string) {
return {
list: () => apiFetch<TItem[]>(`/timetable/constraints/${path}`),
create: (data: TCreate) =>
apiFetch<TItem>(`/timetable/constraints/${path}`, { method: 'POST', body: JSON.stringify(data) }),
remove: (id: string) =>
apiFetch<void>(`/timetable/constraints/${path}/${id}`, { method: 'DELETE' }),
}
}
export const teacherUnavailableDayApi = constraintApi<TeacherUnavailableDay, Omit<TeacherUnavailableDay, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/unavailable-day')
export const teacherUnavailableWindowApi = constraintApi<TeacherUnavailableWindow, Omit<TeacherUnavailableWindow, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/unavailable-window')
export const teacherMaxHoursDayApi = constraintApi<TeacherMaxHoursDay, Omit<TeacherMaxHoursDay, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/max-hours-day')
export const teacherMaxHoursWeekApi = constraintApi<TeacherMaxHoursWeek, Omit<TeacherMaxHoursWeek, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/max-hours-week')
export const teacherExcludedSubjectApi = constraintApi<TeacherExcludedSubject, Omit<TeacherExcludedSubject, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/excluded-subject')
export const teacherExcludedRoomApi = constraintApi<TeacherExcludedRoom, Omit<TeacherExcludedRoom, 'id' | 'created_by_user_id' | 'created_at'>>('teacher/excluded-room')
export const subjectMinDayGapApi = constraintApi<SubjectMinDayGap, Omit<SubjectMinDayGap, 'id' | 'created_by_user_id' | 'created_at'>>('subject/min-day-gap')
export const subjectMaxConsecutiveApi = constraintApi<SubjectMaxConsecutive, Omit<SubjectMaxConsecutive, 'id' | 'created_by_user_id' | 'created_at'>>('subject/max-consecutive')
export const subjectContiguousWhenRepeatedApi = constraintApi<SubjectContiguousWhenRepeated, Omit<SubjectContiguousWhenRepeated, 'id' | 'created_by_user_id' | 'created_at'>>('subject/contiguous-when-repeated')
export const subjectPreferredPeriodApi = constraintApi<SubjectPreferredPeriod, Omit<SubjectPreferredPeriod, 'id' | 'created_by_user_id' | 'created_at'>>('subject/preferred-period')
export const subjectDoubleLessonApi = constraintApi<SubjectDoubleLesson, Omit<SubjectDoubleLesson, 'id' | 'created_by_user_id' | 'created_at'>>('subject/double-lesson')
export const classMaxHoursDayApi = constraintApi<ClassMaxHoursDay, Omit<ClassMaxHoursDay, 'id' | 'created_by_user_id' | 'created_at'>>('class/max-hours-day')
export const classNoGapsApi = constraintApi<ClassNoGaps, Omit<ClassNoGaps, 'id' | 'created_by_user_id' | 'created_at'>>('class/no-gaps')
export const roomRequiresTypeApi = constraintApi<RoomRequiresType, Omit<RoomRequiresType, 'id' | 'created_by_user_id' | 'created_at'>>('room/requires-type')
export const roomUnavailableApi = constraintApi<RoomUnavailable, Omit<RoomUnavailable, 'id' | 'created_by_user_id' | 'created_at'>>('room/unavailable')