Files
backend/internal/model/schedule_course.go

36 lines
1.1 KiB
Go
Raw Normal View History

package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// ScheduleCourse 用户课表课程
type ScheduleCourse struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
UserID string `json:"user_id" gorm:"type:varchar(36);index;not null"`
Name string `json:"name" gorm:"type:varchar(120);not null"`
Teacher string `json:"teacher" gorm:"type:varchar(80)"`
Location string `json:"location" gorm:"type:varchar(120)"`
DayOfWeek int `json:"day_of_week" gorm:"index;not null"` // 0=周一, 6=周日
StartSection int `json:"start_section" gorm:"not null"`
EndSection int `json:"end_section" gorm:"not null"`
Weeks string `json:"weeks" gorm:"type:text;not null"` // JSON 数组字符串
Color string `json:"color" gorm:"type:varchar(20)"`
CreatedAt time.Time
UpdatedAt time.Time
}
func (s *ScheduleCourse) BeforeCreate(tx *gorm.DB) error {
if s.ID == "" {
s.ID = uuid.New().String()
}
return nil
}
func (ScheduleCourse) TableName() string {
return "schedule_courses"
}