Migration 000062 adds lessons.publish_status (DRAFT default for new rows; existing rows published). Editors see all lessons; learners see published-only lists and GET by id. Sequential prerequisites and completion counts ignore drafts. Course lesson_count counts published lessons only. Swagger documents publish_status on create/update bodies. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.8 KiB
Go
74 lines
2.8 KiB
Go
package domain
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// LessonPublishStatus controls learner visibility for an LMS lesson row (like PracticePublishStatus).
|
|
type LessonPublishStatus string
|
|
|
|
const (
|
|
LessonPublishDraft LessonPublishStatus = "DRAFT"
|
|
LessonPublishPublished LessonPublishStatus = "PUBLISHED"
|
|
)
|
|
|
|
// LessonPublishStatusFromDB normalizes persisted values.
|
|
func LessonPublishStatusFromDB(raw string) LessonPublishStatus {
|
|
switch strings.TrimSpace(strings.ToUpper(raw)) {
|
|
case string(LessonPublishPublished):
|
|
return LessonPublishPublished
|
|
default:
|
|
return LessonPublishDraft
|
|
}
|
|
}
|
|
|
|
// LessonPublishStatusFromCreateInput resolves create body: omit → draft; explicit value validated separately.
|
|
func LessonPublishStatusFromCreateInput(raw *string) LessonPublishStatus {
|
|
if raw == nil || strings.TrimSpace(*raw) == "" {
|
|
return LessonPublishDraft
|
|
}
|
|
return LessonPublishStatusFromDB(*raw)
|
|
}
|
|
|
|
// Lesson belongs to a Module.
|
|
type Lesson struct {
|
|
ID int64 `json:"id"`
|
|
ModuleID int64 `json:"module_id"`
|
|
Title string `json:"title"`
|
|
VideoURL *string `json:"video_url,omitempty"`
|
|
Thumbnail *string `json:"thumbnail,omitempty"`
|
|
Description *string `json:"description,omitempty"`
|
|
SortOrder int `json:"sort_order"`
|
|
PublishStatus LessonPublishStatus `json:"publish_status"`
|
|
HasPractice bool `json:"has_practice"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
|
Access *LMSEntityAccess `json:"access,omitempty"`
|
|
}
|
|
|
|
// VisibleToLearners is true when the lesson appears in subscriber/catalog LMS APIs.
|
|
func (l Lesson) VisibleToLearners() bool {
|
|
return l.PublishStatus == LessonPublishPublished
|
|
}
|
|
|
|
type CreateLessonInput struct {
|
|
Title string `json:"title" validate:"required"`
|
|
VideoURL *string `json:"video_url,omitempty"`
|
|
Thumbnail *string `json:"thumbnail,omitempty"`
|
|
Description *string `json:"description,omitempty"`
|
|
// SortOrder within the module when set; omit to append after current max within module_id.
|
|
SortOrder *int `json:"sort_order,omitempty" validate:"omitempty,min=0"`
|
|
// Omit or empty defaults to DRAFT; set PUBLISHED to make visible to learners immediately.
|
|
PublishStatus *string `json:"publish_status,omitempty" validate:"omitempty,oneof=DRAFT draft PUBLISHED published"`
|
|
}
|
|
|
|
type UpdateLessonInput struct {
|
|
Title *string `json:"title,omitempty"`
|
|
VideoURL *string `json:"video_url,omitempty"`
|
|
Thumbnail *string `json:"thumbnail,omitempty"`
|
|
Description *string `json:"description,omitempty"`
|
|
SortOrder *int `json:"sort_order,omitempty"`
|
|
PublishStatus *string `json:"publish_status,omitempty" validate:"omitempty,oneof=DRAFT draft PUBLISHED published"`
|
|
}
|