Introduce exam_prep.practice_parents, migrate lesson links, and add create/list APIs with progress rollups, sequential gating, and RBAC permissions. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
3.6 KiB
Go
87 lines
3.6 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
// ExamPrepParentKind identifies which exam-prep hierarchy entity a practice is linked to.
|
|
type ExamPrepParentKind string
|
|
|
|
const (
|
|
ExamPrepParentKindCatalogCourse ExamPrepParentKind = "CATALOG_COURSE"
|
|
ExamPrepParentKindUnit ExamPrepParentKind = "UNIT"
|
|
ExamPrepParentKindLesson ExamPrepParentKind = "LESSON"
|
|
)
|
|
|
|
// ExamPrepPracticeParent links a practice to a catalog course, unit, or lesson.
|
|
type ExamPrepPracticeParent struct {
|
|
Kind ExamPrepParentKind `json:"parent_kind"`
|
|
ID int64 `json:"parent_id"`
|
|
}
|
|
|
|
// ExamPrepPractice is question-set content tied to an exam-prep parent; uses shared question_sets / questions.
|
|
type ExamPrepPractice struct {
|
|
ID int64 `json:"id"`
|
|
Parents *[]ExamPrepPracticeParent `json:"parents,omitempty"`
|
|
LessonID *int64 `json:"lesson_id,omitempty"`
|
|
Title string `json:"title"`
|
|
StoryDescription *string `json:"story_description,omitempty"`
|
|
StoryImage *string `json:"story_image,omitempty"`
|
|
PersonaID *int64 `json:"persona_id,omitempty"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
PublishStatus PracticePublishStatus `json:"publish_status"`
|
|
QuickTips *string `json:"quick_tips,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
|
}
|
|
|
|
// ExamPrepPracticeParentsDeref returns parents or nil when unset.
|
|
func ExamPrepPracticeParentsDeref(parents *[]ExamPrepPracticeParent) []ExamPrepPracticeParent {
|
|
if parents == nil {
|
|
return nil
|
|
}
|
|
return *parents
|
|
}
|
|
|
|
// ExamPrepPracticeParentsPtr returns a pointer to a copy of parents, or nil when empty.
|
|
func ExamPrepPracticeParentsPtr(parents []ExamPrepPracticeParent) *[]ExamPrepPracticeParent {
|
|
if len(parents) == 0 {
|
|
return nil
|
|
}
|
|
cp := append([]ExamPrepPracticeParent(nil), parents...)
|
|
return &cp
|
|
}
|
|
|
|
// ExamPrepPracticePrimaryParent returns the single parent when exactly one is set.
|
|
func ExamPrepPracticePrimaryParent(p ExamPrepPractice) (ExamPrepPracticeParent, bool) {
|
|
parents := ExamPrepPracticeParentsDeref(p.Parents)
|
|
if len(parents) != 1 {
|
|
return ExamPrepPracticeParent{}, false
|
|
}
|
|
return parents[0], true
|
|
}
|
|
|
|
// VisibleToLearners mirrors LMS practice visibility rules for subscribers.
|
|
func (p ExamPrepPractice) VisibleToLearners() bool {
|
|
return p.PublishStatus == PracticePublishPublished
|
|
}
|
|
|
|
// CreateExamPrepPracticeInput is the body for POST .../exam-prep/{parent}/practices.
|
|
type CreateExamPrepPracticeInput struct {
|
|
Title *string `json:"title,omitempty"`
|
|
StoryDescription *string `json:"story_description,omitempty"`
|
|
StoryImage *string `json:"story_image,omitempty"`
|
|
PersonaID *int64 `json:"persona_id,omitempty"`
|
|
QuestionSetID int64 `json:"question_set_id" validate:"required,gt=0"`
|
|
QuickTips *string `json:"quick_tips,omitempty"`
|
|
PublishStatus string `json:"publish_status,omitempty" validate:"omitempty,oneof=DRAFT draft PUBLISHED published"`
|
|
}
|
|
|
|
type UpdateExamPrepPracticeInput struct {
|
|
Title *string `json:"title,omitempty"`
|
|
StoryDescription *string `json:"story_description,omitempty"`
|
|
StoryImage *string `json:"story_image,omitempty"`
|
|
PersonaID *int64 `json:"persona_id,omitempty"`
|
|
QuestionSetID *int64 `json:"question_set_id,omitempty"`
|
|
QuickTips *string `json:"quick_tips,omitempty"`
|
|
PublishStatus *string `json:"publish_status,omitempty" validate:"omitempty,oneof=DRAFT draft PUBLISHED published"`
|
|
}
|