73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
// Code generated by summer make. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// CalendarFeed is a student's subscribable ICS calendar: a secret token
|
|
// that makes the URL private, and the student's choice of what the feed
|
|
// lists. One feed per user (a golem15.user users row).
|
|
type CalendarFeed struct {
|
|
ID uint `gorm:"column:id;primaryKey"`
|
|
UserID uint `gorm:"column:user_id"`
|
|
// Token is 32 random bytes in hex. The feed is read-only and low in
|
|
// sensitivity, so the token is stored as it is.
|
|
Token string `gorm:"column:token"`
|
|
// ExcludedCourseIDs are the courses the feed leaves out, such as the
|
|
// elective alternatives the student did not choose.
|
|
ExcludedCourseIDs IDList `gorm:"column:excluded_course_ids"`
|
|
IncludeMeetings bool `gorm:"column:include_meetings"`
|
|
IncludeDeadlines bool `gorm:"column:include_deadlines"`
|
|
LastFetchedAt *time.Time `gorm:"column:last_fetched_at"`
|
|
CreatedAt time.Time `gorm:"column:created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at"`
|
|
}
|
|
|
|
// TableName is the plugin table.
|
|
func (CalendarFeed) TableName() string { return "jz_bm_calendar_feeds" }
|
|
|
|
// IDList is a JSONB array of IDs. A nil list is stored as [].
|
|
type IDList []uint
|
|
|
|
// Value stores the list as a JSON array.
|
|
func (l IDList) Value() (driver.Value, error) {
|
|
if l == nil {
|
|
return "[]", nil
|
|
}
|
|
b, err := json.Marshal([]uint(l))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
// Scan reads a JSON array; NULL is an empty list.
|
|
func (l *IDList) Scan(src any) error {
|
|
var raw []byte
|
|
switch v := src.(type) {
|
|
case nil:
|
|
*l = IDList{}
|
|
return nil
|
|
case string:
|
|
raw = []byte(v)
|
|
case []byte:
|
|
raw = v
|
|
default:
|
|
return fmt.Errorf("jz.bm: cannot scan %T into IDList", src)
|
|
}
|
|
var ids []uint
|
|
if err := json.Unmarshal(raw, &ids); err != nil {
|
|
return fmt.Errorf("jz.bm: IDList: %w", err)
|
|
}
|
|
if ids == nil {
|
|
ids = []uint{}
|
|
}
|
|
*l = ids
|
|
return nil
|
|
}
|