The schedule showed a lecturer only where the session notes named one (Globalizacja), so the student plan had nobody under the other courses. The session JSON now carries the course lecturer in its course ref and an optional per-session lecturer (new nullable column, admin field, seed key) for courses shared between two people. The student app shows the session's own lecturer or, failing that, the course's.
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
// Code generated by summer make. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ClassSession is one block of classes (zajęcia) of a course.
|
|
type ClassSession struct {
|
|
ID uint `gorm:"column:id;primaryKey"`
|
|
CourseID *uint `gorm:"column:course_id"`
|
|
Course *Course `gorm:"foreignKey:CourseID"`
|
|
MeetingID *uint `gorm:"column:meeting_id"`
|
|
Meeting *Meeting `gorm:"foreignKey:MeetingID"`
|
|
StartsAt time.Time `gorm:"column:starts_at"`
|
|
EndsAt time.Time `gorm:"column:ends_at"`
|
|
Room *string `gorm:"column:room"`
|
|
Kind *string `gorm:"column:kind"`
|
|
Lecturer *string `gorm:"column:lecturer"`
|
|
Notes *string `gorm:"column:notes"`
|
|
IsOnline bool `gorm:"column:is_online"`
|
|
CreatedAt time.Time `gorm:"column:created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at"`
|
|
}
|
|
|
|
// TableName is the plugin table.
|
|
func (ClassSession) TableName() string { return "jz_bm_class_sessions" }
|
|
|
|
// Fillable lists the columns mass assignment may set. course_id and
|
|
// meeting_id are set through the admin relation pickers.
|
|
func (ClassSession) Fillable() []string {
|
|
return []string{"course_id", "meeting_id", "starts_at", "ends_at", "room", "kind", "lecturer", "notes", "is_online"}
|
|
}
|
|
|
|
// Rules are checked by the admin API on every save.
|
|
func (ClassSession) Rules() map[string]string {
|
|
return map[string]string{
|
|
"starts_at": "required",
|
|
"ends_at": "required",
|
|
"room": "nullable|max:100",
|
|
"kind": "nullable|max:100",
|
|
"lecturer": "nullable|max:255",
|
|
"is_online": "boolean",
|
|
}
|
|
}
|
|
|
|
// TemporalErrors checks that the session ends after it starts, which
|
|
// lagoon.Validate cannot. The required rules cover missing times.
|
|
func (s *ClassSession) TemporalErrors() map[string][]string {
|
|
e := temporalErrors{}
|
|
if !s.StartsAt.IsZero() && !s.EndsAt.IsZero() && !s.EndsAt.After(s.StartsAt) {
|
|
e.add("ends_at", "The ends at must be a date after starts at.")
|
|
}
|
|
return e.result()
|
|
}
|
|
|
|
// BeforeSave stores NULL for empty optional text.
|
|
func (s *ClassSession) BeforeSave(*gorm.DB) error {
|
|
blank(&s.Room, &s.Kind, &s.Lecturer, &s.Notes)
|
|
return nil
|
|
}
|