Datepickers on native time.Time / lagoon.Date fields, file uploads on materials, readings and class sessions managed from the course form (course_id made nullable).
63 lines
2.0 KiB
Go
63 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 time.Time `gorm:"column:starts_at"`
|
|
EndsAt time.Time `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 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.Notes)
|
|
return nil
|
|
}
|