Files
sm-bm-plugin/models/checklist_item.go
Jakub Zych d7cd5baedf feat: private checklists for zjazd preparation
Per-user checklists with items that may link a course, reading, deadline,
material or own presentation deck. An item with a reading shares the
reading's read mark. Student API routes with token twins, MCP tools,
migrations, tests and README.
2026-10-30 12:41:04 +01:00

65 lines
2.6 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
// ChecklistItemKinds lists the allowed ChecklistItem.Kind values.
var ChecklistItemKinds = []string{"lektura", "artykul", "ksiazka", "prezentacja", "zadanie", "inne"}
// ChecklistItem is one entry of a Checklist. It may point at a reading, a
// deadline, a material or a course, and name a deck of golem15.presentations
// by slug. An item with a reading is done when the checklist's owner has
// read it (ReadingProgress); any other item is done when DoneAt is set.
type ChecklistItem struct {
ID uint `gorm:"column:id;primaryKey"`
ChecklistID uint `gorm:"column:checklist_id"`
Kind string `gorm:"column:kind"`
Title string `gorm:"column:title"`
Notes *string `gorm:"column:notes"`
URL *string `gorm:"column:url"`
CourseID *uint `gorm:"column:course_id"`
ReadingID *uint `gorm:"column:reading_id"`
DeadlineID *uint `gorm:"column:deadline_id"`
MaterialID *uint `gorm:"column:material_id"`
PresentationSlug *string `gorm:"column:presentation_slug"`
DueAt *time.Time `gorm:"column:due_at"`
EstimateMinutes *int `gorm:"column:estimate_minutes"`
SortOrder int `gorm:"column:sort_order"`
DoneAt *time.Time `gorm:"column:done_at"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
// TableName is the plugin table.
func (ChecklistItem) TableName() string { return "jz_bm_checklist_items" }
// Fillable lists the columns the student API may set. checklist_id moves an
// item to another of the caller's checklists; done_at is set by the done
// routes only.
func (ChecklistItem) Fillable() []string {
return []string{"checklist_id", "kind", "title", "notes", "url", "course_id", "reading_id", "deadline_id",
"material_id", "presentation_slug", "due_at", "estimate_minutes", "sort_order"}
}
// Rules are checked by the student API on every save.
func (ChecklistItem) Rules() map[string]string {
return map[string]string{
"kind": "required|in:lektura,artykul,ksiazka,prezentacja,zadanie,inne",
"title": "required|max:500",
"notes": "nullable|max:10000",
"url": "nullable|max:2048",
"presentation_slug": "nullable|max:255",
"estimate_minutes": "nullable|integer|min:0|max:10000",
"sort_order": "nullable|integer",
}
}
// BeforeSave stores NULL for empty optional text.
func (i *ChecklistItem) BeforeSave(*gorm.DB) error {
blank(&i.Notes, &i.URL, &i.PresentationSlug)
return nil
}