fix: return exam-prep catalog and unit parents in question type practice list
The practices-by-question-type endpoint only exposed exam_prep_lesson_id, so catalog course and unit links appeared unlinked in the admin panel. Now returns exam_prep_parents for all exam-prep parent kinds. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
218c09c904
commit
a52394825a
|
|
@ -61,13 +61,7 @@ WITH matched AS (
|
|||
p.persona_id,
|
||||
p.quick_tips,
|
||||
p.publish_status,
|
||||
(
|
||||
SELECT pp.parent_id
|
||||
FROM exam_prep.practice_parents pp
|
||||
WHERE pp.practice_id = p.id
|
||||
AND pp.parent_kind = 'LESSON'
|
||||
LIMIT 1
|
||||
) AS exam_prep_lesson_id,
|
||||
NULL::bigint AS exam_prep_lesson_id,
|
||||
p.created_at,
|
||||
p.updated_at,
|
||||
(
|
||||
|
|
|
|||
|
|
@ -74,13 +74,7 @@ WITH matched AS (
|
|||
p.persona_id,
|
||||
p.quick_tips,
|
||||
p.publish_status,
|
||||
(
|
||||
SELECT pp.parent_id
|
||||
FROM exam_prep.practice_parents pp
|
||||
WHERE pp.practice_id = p.id
|
||||
AND pp.parent_kind = 'LESSON'
|
||||
LIMIT 1
|
||||
) AS exam_prep_lesson_id,
|
||||
NULL::bigint AS exam_prep_lesson_id,
|
||||
p.created_at,
|
||||
p.updated_at,
|
||||
(
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ type PracticeByQuestionTypeDefinition struct {
|
|||
StoryImage *string `json:"story_image,omitempty"`
|
||||
PersonaID *int64 `json:"persona_id,omitempty"`
|
||||
QuickTips *string `json:"quick_tips,omitempty"`
|
||||
PublishStatus PracticePublishStatus `json:"publish_status"`
|
||||
Parents *[]PracticeParent `json:"parents"`
|
||||
ExamPrepLessonID *int64 `json:"exam_prep_lesson_id,omitempty"`
|
||||
PublishStatus PracticePublishStatus `json:"publish_status"`
|
||||
Parents *[]PracticeParent `json:"parents"`
|
||||
ExamPrepParents *[]ExamPrepPracticeParent `json:"exam_prep_parents"`
|
||||
ExamPrepLessonID *int64 `json:"exam_prep_lesson_id,omitempty"`
|
||||
MatchingQuestionCount int64 `json:"matching_question_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
|
|
|
|||
|
|
@ -1366,7 +1366,11 @@ func (s *Store) ReorderQuestionSets(ctx context.Context, ids []int64, positions
|
|||
})
|
||||
}
|
||||
|
||||
func practiceByQuestionTypeRowToDomain(r dbgen.ListPracticesByQuestionTypeDefinitionRow, parents []domain.PracticeParent) domain.PracticeByQuestionTypeDefinition {
|
||||
func practiceByQuestionTypeRowToDomain(
|
||||
r dbgen.ListPracticesByQuestionTypeDefinitionRow,
|
||||
lmsParents []domain.PracticeParent,
|
||||
examPrepParents []domain.ExamPrepPracticeParent,
|
||||
) domain.PracticeByQuestionTypeDefinition {
|
||||
out := domain.PracticeByQuestionTypeDefinition{
|
||||
PracticeKind: r.PracticeKind,
|
||||
PracticeID: r.PracticeID,
|
||||
|
|
@ -1382,10 +1386,16 @@ func practiceByQuestionTypeRowToDomain(r dbgen.ListPracticesByQuestionTypeDefini
|
|||
UpdatedAt: timePtr(r.UpdatedAt),
|
||||
}
|
||||
if r.PracticeKind == "LMS" {
|
||||
out.Parents = domain.PracticeParentsPtr(parents)
|
||||
} else if r.ExamPrepLessonID.Valid {
|
||||
id := r.ExamPrepLessonID.Int64
|
||||
out.ExamPrepLessonID = &id
|
||||
out.Parents = domain.PracticeParentsPtr(lmsParents)
|
||||
return out
|
||||
}
|
||||
out.ExamPrepParents = domain.ExamPrepPracticeParentsPtr(examPrepParents)
|
||||
for _, parent := range examPrepParents {
|
||||
if parent.Kind == domain.ExamPrepParentKindLesson {
|
||||
id := parent.ID
|
||||
out.ExamPrepLessonID = &id
|
||||
break
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
|
@ -1414,9 +1424,12 @@ func (s *Store) ListPracticesByQuestionTypeDefinition(
|
|||
return []domain.PracticeByQuestionTypeDefinition{}, 0, nil
|
||||
}
|
||||
lmsPracticeIDs := make([]int64, 0)
|
||||
examPrepPracticeIDs := make([]int64, 0)
|
||||
for _, row := range rows {
|
||||
if row.PracticeKind == "LMS" {
|
||||
lmsPracticeIDs = append(lmsPracticeIDs, row.PracticeID)
|
||||
} else if row.PracticeKind == "EXAM_PREP" {
|
||||
examPrepPracticeIDs = append(examPrepPracticeIDs, row.PracticeID)
|
||||
}
|
||||
}
|
||||
parentsByPracticeID := make(map[int64][]domain.PracticeParent)
|
||||
|
|
@ -1429,13 +1442,30 @@ func (s *Store) ListPracticesByQuestionTypeDefinition(
|
|||
parentsByPracticeID[row.PracticeID] = append(parentsByPracticeID[row.PracticeID], lmsPracticeParentFromDB(row))
|
||||
}
|
||||
}
|
||||
examPrepParentsByPracticeID := make(map[int64][]domain.ExamPrepPracticeParent)
|
||||
if len(examPrepPracticeIDs) > 0 {
|
||||
parentRows, err := s.queries.ListExamPrepPracticeParentsByPracticeIDs(ctx, examPrepPracticeIDs)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
for _, row := range parentRows {
|
||||
examPrepParentsByPracticeID[row.PracticeID] = append(
|
||||
examPrepParentsByPracticeID[row.PracticeID],
|
||||
examPrepPracticeParentFromDB(row),
|
||||
)
|
||||
}
|
||||
}
|
||||
out := make([]domain.PracticeByQuestionTypeDefinition, len(rows))
|
||||
var total int64
|
||||
for i, row := range rows {
|
||||
if i == 0 {
|
||||
total = row.TotalCount
|
||||
}
|
||||
out[i] = practiceByQuestionTypeRowToDomain(row, parentsByPracticeID[row.PracticeID])
|
||||
out[i] = practiceByQuestionTypeRowToDomain(
|
||||
row,
|
||||
parentsByPracticeID[row.PracticeID],
|
||||
examPrepParentsByPracticeID[row.PracticeID],
|
||||
)
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user