Files
sm-bm-plugin/models/class_session.go
Jakub Zych 1046237771 feat: add the study data models and schema migrations
Courses, meetings, class sessions, deadlines, readings with per-user
progress, materials with tags and file attachments. Timestamps are
stored in UTC and held as Europe/Warsaw text so the admin text inputs
can write them.
2026-10-02 14:26:08 +02:00

64 lines
2.0 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 DateTime `gorm:"column:starts_at"`
EndsAt DateTime `gorm:"column:ends_at"`
Room *string `gorm:"column:room"`
Kind *string `gorm:"column:kind"`
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", "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",
"is_online": "boolean",
}
}
// TemporalErrors checks the timestamps, which lagoon.Validate cannot.
func (s *ClassSession) TemporalErrors() map[string][]string {
e := temporalErrors{}
e.dateTime("starts_at", s.StartsAt, true)
e.dateTime("ends_at", s.EndsAt, true)
if len(e) == 0 && !s.EndsAt.MustTime().After(s.StartsAt.MustTime()) {
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.Notes)
return nil
}