The Pulpit hero lists what to read for the current or next zjazd, so readings and materials get a nullable meeting_id (FK to jz_bm_meetings, ON DELETE SET NULL, indexed). The reading admin form gets a "Na zjazd" picker, the student reading JSON carries meeting_id, and the management /readings records filter and validate it.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
// Code generated by summer make. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Reading is one lektura on a course's reading list.
|
|
type Reading 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"`
|
|
Title string `gorm:"column:title"`
|
|
Author *string `gorm:"column:author"`
|
|
Source *string `gorm:"column:source"`
|
|
URL *string `gorm:"column:url"`
|
|
IsRequired bool `gorm:"column:is_required"`
|
|
SortOrder int `gorm:"column:sort_order"`
|
|
CreatedAt time.Time `gorm:"column:created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at"`
|
|
}
|
|
|
|
// TableName is the plugin table.
|
|
func (Reading) TableName() string { return "jz_bm_readings" }
|
|
|
|
// Fillable lists the columns mass assignment may set.
|
|
func (Reading) Fillable() []string {
|
|
return []string{"course_id", "meeting_id", "title", "author", "source", "url", "is_required", "sort_order"}
|
|
}
|
|
|
|
// Rules are checked by the admin API on every save.
|
|
func (Reading) Rules() map[string]string {
|
|
return map[string]string{
|
|
"title": "required|max:500",
|
|
"author": "nullable|max:255",
|
|
"source": "nullable|max:500",
|
|
"url": "nullable|max:2048",
|
|
"is_required": "boolean",
|
|
"sort_order": "nullable|integer",
|
|
}
|
|
}
|
|
|
|
// BeforeSave stores NULL for empty optional text.
|
|
func (r *Reading) BeforeSave(*gorm.DB) error {
|
|
blank(&r.Author, &r.Source, &r.URL)
|
|
return nil
|
|
}
|