Files
breakpilot-lehrer/school-service/internal/models/timetable.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

156 lines
6.6 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
)
// TimetableClass is a school class managed for timetabling.
// Separate from the per-teacher `classes` table because timetabling is school-wide.
type TimetableClass struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedByUserID uuid.UUID `json:"created_by_user_id" db:"created_by_user_id"`
Name string `json:"name" db:"name"`
GradeLevel int `json:"grade_level" db:"grade_level"`
StudentCount int `json:"student_count" db:"student_count"`
Notes string `json:"notes,omitempty" db:"notes"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// TimetablePeriod is one time slot in the weekly grid.
// DayOfWeek: 1=Mon..7=Sun. PeriodIndex: 1=first lesson of the day.
type TimetablePeriod struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedByUserID uuid.UUID `json:"created_by_user_id" db:"created_by_user_id"`
DayOfWeek int `json:"day_of_week" db:"day_of_week"`
PeriodIndex int `json:"period_index" db:"period_index"`
StartTime string `json:"start_time" db:"start_time"`
EndTime string `json:"end_time" db:"end_time"`
IsBreak bool `json:"is_break" db:"is_break"`
Label string `json:"label,omitempty" db:"label"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// TimetableRoom is a physical room that can host lessons.
type TimetableRoom struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedByUserID uuid.UUID `json:"created_by_user_id" db:"created_by_user_id"`
Name string `json:"name" db:"name"`
RoomType string `json:"room_type,omitempty" db:"room_type"`
Capacity int `json:"capacity" db:"capacity"`
FloorLevel int `json:"floor_level" db:"floor_level"`
HasElevator bool `json:"has_elevator" db:"has_elevator"`
Notes string `json:"notes,omitempty" db:"notes"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// TimetableSubject is a school-wide subject for timetabling.
type TimetableSubject struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedByUserID uuid.UUID `json:"created_by_user_id" db:"created_by_user_id"`
Name string `json:"name" db:"name"`
ShortCode string `json:"short_code" db:"short_code"`
Color string `json:"color,omitempty" db:"color"`
IsMainSubject bool `json:"is_main_subject" db:"is_main_subject"`
RequiredRoomType string `json:"required_room_type,omitempty" db:"required_room_type"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// TimetableTeacher is a teacher as a schedulable resource.
// Independent from BreakPilot users — the Rektor enters all teachers manually.
type TimetableTeacher struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedByUserID uuid.UUID `json:"created_by_user_id" db:"created_by_user_id"`
FirstName string `json:"first_name" db:"first_name"`
LastName string `json:"last_name" db:"last_name"`
ShortCode string `json:"short_code" db:"short_code"`
EmploymentPercentage int `json:"employment_percentage" db:"employment_percentage"`
MaxHoursWeek int `json:"max_hours_week" db:"max_hours_week"`
Notes string `json:"notes,omitempty" db:"notes"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// TimetableCurriculum links a class to a subject with the weekly hour count.
type TimetableCurriculum struct {
ID uuid.UUID `json:"id" db:"id"`
ClassID uuid.UUID `json:"class_id" db:"class_id"`
SubjectID uuid.UUID `json:"subject_id" db:"subject_id"`
WeeklyHours int `json:"weekly_hours" db:"weekly_hours"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
// Joined fields
SubjectName string `json:"subject_name,omitempty"`
ClassName string `json:"class_name,omitempty"`
}
// TimetableAssignment is the teaching contract: who teaches what subject in which class.
type TimetableAssignment struct {
ID uuid.UUID `json:"id" db:"id"`
TeacherID uuid.UUID `json:"teacher_id" db:"teacher_id"`
ClassID uuid.UUID `json:"class_id" db:"class_id"`
SubjectID uuid.UUID `json:"subject_id" db:"subject_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
// Joined fields
TeacherName string `json:"teacher_name,omitempty"`
ClassName string `json:"class_name,omitempty"`
SubjectName string `json:"subject_name,omitempty"`
}
// Request DTOs
type CreateTimetableClassRequest struct {
Name string `json:"name" binding:"required"`
GradeLevel int `json:"grade_level" binding:"required,min=1,max=13"`
StudentCount int `json:"student_count" binding:"min=0"`
Notes string `json:"notes"`
}
type CreateTimetablePeriodRequest struct {
DayOfWeek int `json:"day_of_week" binding:"required,min=1,max=7"`
PeriodIndex int `json:"period_index" binding:"required,min=1"`
StartTime string `json:"start_time" binding:"required"`
EndTime string `json:"end_time" binding:"required"`
IsBreak bool `json:"is_break"`
Label string `json:"label"`
}
type CreateTimetableRoomRequest struct {
Name string `json:"name" binding:"required"`
RoomType string `json:"room_type"`
Capacity int `json:"capacity"`
FloorLevel int `json:"floor_level"`
HasElevator bool `json:"has_elevator"`
Notes string `json:"notes"`
}
type CreateTimetableSubjectRequest struct {
Name string `json:"name" binding:"required"`
ShortCode string `json:"short_code" binding:"required"`
Color string `json:"color"`
IsMainSubject bool `json:"is_main_subject"`
RequiredRoomType string `json:"required_room_type"`
}
type CreateTimetableTeacherRequest struct {
FirstName string `json:"first_name" binding:"required"`
LastName string `json:"last_name" binding:"required"`
ShortCode string `json:"short_code" binding:"required"`
EmploymentPercentage int `json:"employment_percentage" binding:"min=0,max=100"`
MaxHoursWeek int `json:"max_hours_week" binding:"min=0"`
Notes string `json:"notes"`
}
type CreateTimetableCurriculumRequest struct {
ClassID string `json:"class_id" binding:"required,uuid"`
SubjectID string `json:"subject_id" binding:"required,uuid"`
WeeklyHours int `json:"weekly_hours" binding:"required,min=1,max=10"`
}
type CreateTimetableAssignmentRequest struct {
TeacherID string `json:"teacher_id" binding:"required,uuid"`
ClassID string `json:"class_id" binding:"required,uuid"`
SubjectID string `json:"subject_id" binding:"required,uuid"`
}