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.
This commit is contained in:
72
models/course.go
Normal file
72
models/course.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Course forms, the values of Course.Form.
|
||||
const (
|
||||
FormWyklad = "wyklad"
|
||||
FormCwiczenia = "cwiczenia"
|
||||
FormKonwersatorium = "konwersatorium"
|
||||
FormSeminarium = "seminarium"
|
||||
FormInne = "inne"
|
||||
)
|
||||
|
||||
// CourseForms lists the allowed Course.Form values.
|
||||
var CourseForms = []string{FormWyklad, FormCwiczenia, FormKonwersatorium, FormSeminarium, FormInne}
|
||||
|
||||
// Course is one przedmiot of the programme in one form (a lecture and its
|
||||
// tutorial are two courses).
|
||||
type Course struct {
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
Code *string `gorm:"column:code"`
|
||||
Name string `gorm:"column:name"`
|
||||
Form string `gorm:"column:form"`
|
||||
Lecturer *string `gorm:"column:lecturer"`
|
||||
Semester int `gorm:"column:semester"`
|
||||
ECTS *float64 `gorm:"column:ects"`
|
||||
Assessment *string `gorm:"column:assessment"`
|
||||
// ElectiveGroup marks alternatives ("do wyboru"): courses that share a
|
||||
// value are options of one choice, such as "specjalnosc".
|
||||
ElectiveGroup *string `gorm:"column:elective_group"`
|
||||
Description *string `gorm:"column:description"`
|
||||
SyllabusURL *string `gorm:"column:syllabus_url"`
|
||||
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 (Course) TableName() string { return "jz_bm_courses" }
|
||||
|
||||
// Fillable lists the columns mass assignment may set.
|
||||
func (Course) Fillable() []string {
|
||||
return []string{"code", "name", "form", "lecturer", "semester", "ects", "assessment", "elective_group", "description", "syllabus_url", "sort_order"}
|
||||
}
|
||||
|
||||
// Rules are checked by the admin API on every save.
|
||||
func (Course) Rules() map[string]string {
|
||||
return map[string]string{
|
||||
"code": "nullable|max:50",
|
||||
"name": "required|max:255",
|
||||
"form": "required|in:wyklad,cwiczenia,konwersatorium,seminarium,inne",
|
||||
"lecturer": "nullable|max:255",
|
||||
"semester": "required|integer|between:1,4",
|
||||
"ects": "nullable|numeric|between:0,60",
|
||||
"assessment": "nullable|max:100",
|
||||
"elective_group": "nullable|max:100",
|
||||
"syllabus_url": "nullable|max:2048",
|
||||
"sort_order": "nullable|integer",
|
||||
}
|
||||
}
|
||||
|
||||
// BeforeSave stores NULL for empty optional text.
|
||||
func (c *Course) BeforeSave(*gorm.DB) error {
|
||||
blank(&c.Code, &c.Lecturer, &c.Assessment, &c.ElectiveGroup, &c.Description, &c.SyllabusURL)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user