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.persona_id,
|
||||||
p.quick_tips,
|
p.quick_tips,
|
||||||
p.publish_status,
|
p.publish_status,
|
||||||
(
|
NULL::bigint AS exam_prep_lesson_id,
|
||||||
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,
|
|
||||||
p.created_at,
|
p.created_at,
|
||||||
p.updated_at,
|
p.updated_at,
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -74,13 +74,7 @@ WITH matched AS (
|
||||||
p.persona_id,
|
p.persona_id,
|
||||||
p.quick_tips,
|
p.quick_tips,
|
||||||
p.publish_status,
|
p.publish_status,
|
||||||
(
|
NULL::bigint AS exam_prep_lesson_id,
|
||||||
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,
|
|
||||||
p.created_at,
|
p.created_at,
|
||||||
p.updated_at,
|
p.updated_at,
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,10 @@ type PracticeByQuestionTypeDefinition struct {
|
||||||
StoryImage *string `json:"story_image,omitempty"`
|
StoryImage *string `json:"story_image,omitempty"`
|
||||||
PersonaID *int64 `json:"persona_id,omitempty"`
|
PersonaID *int64 `json:"persona_id,omitempty"`
|
||||||
QuickTips *string `json:"quick_tips,omitempty"`
|
QuickTips *string `json:"quick_tips,omitempty"`
|
||||||
PublishStatus PracticePublishStatus `json:"publish_status"`
|
PublishStatus PracticePublishStatus `json:"publish_status"`
|
||||||
Parents *[]PracticeParent `json:"parents"`
|
Parents *[]PracticeParent `json:"parents"`
|
||||||
ExamPrepLessonID *int64 `json:"exam_prep_lesson_id,omitempty"`
|
ExamPrepParents *[]ExamPrepPracticeParent `json:"exam_prep_parents"`
|
||||||
|
ExamPrepLessonID *int64 `json:"exam_prep_lesson_id,omitempty"`
|
||||||
MatchingQuestionCount int64 `json:"matching_question_count"`
|
MatchingQuestionCount int64 `json:"matching_question_count"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
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{
|
out := domain.PracticeByQuestionTypeDefinition{
|
||||||
PracticeKind: r.PracticeKind,
|
PracticeKind: r.PracticeKind,
|
||||||
PracticeID: r.PracticeID,
|
PracticeID: r.PracticeID,
|
||||||
|
|
@ -1382,10 +1386,16 @@ func practiceByQuestionTypeRowToDomain(r dbgen.ListPracticesByQuestionTypeDefini
|
||||||
UpdatedAt: timePtr(r.UpdatedAt),
|
UpdatedAt: timePtr(r.UpdatedAt),
|
||||||
}
|
}
|
||||||
if r.PracticeKind == "LMS" {
|
if r.PracticeKind == "LMS" {
|
||||||
out.Parents = domain.PracticeParentsPtr(parents)
|
out.Parents = domain.PracticeParentsPtr(lmsParents)
|
||||||
} else if r.ExamPrepLessonID.Valid {
|
return out
|
||||||
id := r.ExamPrepLessonID.Int64
|
}
|
||||||
out.ExamPrepLessonID = &id
|
out.ExamPrepParents = domain.ExamPrepPracticeParentsPtr(examPrepParents)
|
||||||
|
for _, parent := range examPrepParents {
|
||||||
|
if parent.Kind == domain.ExamPrepParentKindLesson {
|
||||||
|
id := parent.ID
|
||||||
|
out.ExamPrepLessonID = &id
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
@ -1414,9 +1424,12 @@ func (s *Store) ListPracticesByQuestionTypeDefinition(
|
||||||
return []domain.PracticeByQuestionTypeDefinition{}, 0, nil
|
return []domain.PracticeByQuestionTypeDefinition{}, 0, nil
|
||||||
}
|
}
|
||||||
lmsPracticeIDs := make([]int64, 0)
|
lmsPracticeIDs := make([]int64, 0)
|
||||||
|
examPrepPracticeIDs := make([]int64, 0)
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
if row.PracticeKind == "LMS" {
|
if row.PracticeKind == "LMS" {
|
||||||
lmsPracticeIDs = append(lmsPracticeIDs, row.PracticeID)
|
lmsPracticeIDs = append(lmsPracticeIDs, row.PracticeID)
|
||||||
|
} else if row.PracticeKind == "EXAM_PREP" {
|
||||||
|
examPrepPracticeIDs = append(examPrepPracticeIDs, row.PracticeID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentsByPracticeID := make(map[int64][]domain.PracticeParent)
|
parentsByPracticeID := make(map[int64][]domain.PracticeParent)
|
||||||
|
|
@ -1429,13 +1442,30 @@ func (s *Store) ListPracticesByQuestionTypeDefinition(
|
||||||
parentsByPracticeID[row.PracticeID] = append(parentsByPracticeID[row.PracticeID], lmsPracticeParentFromDB(row))
|
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))
|
out := make([]domain.PracticeByQuestionTypeDefinition, len(rows))
|
||||||
var total int64
|
var total int64
|
||||||
for i, row := range rows {
|
for i, row := range rows {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
total = row.TotalCount
|
total = row.TotalCount
|
||||||
}
|
}
|
||||||
out[i] = practiceByQuestionTypeRowToDomain(row, parentsByPracticeID[row.PracticeID])
|
out[i] = practiceByQuestionTypeRowToDomain(
|
||||||
|
row,
|
||||||
|
parentsByPracticeID[row.PracticeID],
|
||||||
|
examPrepParentsByPracticeID[row.PracticeID],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return out, total, nil
|
return out, total, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user