course practice count fix

This commit is contained in:
Yared Yemane 2026-04-25 02:41:34 -07:00
parent 5857fce9a0
commit 526426d9f9
3 changed files with 12 additions and 3 deletions

View File

@ -55,13 +55,17 @@ SELECT
INNER JOIN modules m ON l.module_id = m.id
WHERE
m.course_id = c.id) AS lesson_count,
-- Practices whose parent is the course only (lms_practices.course_id). Excludes
-- practices linked via module_id or lesson_id, even for modules/lessons in this course.
(
SELECT
COUNT(*)::bigint
FROM
lms_practices p
WHERE
p.course_id = c.id) AS practice_count
p.course_id = c.id
AND p.module_id IS NULL
AND p.lesson_id IS NULL) AS practice_count
FROM
courses c
WHERE

View File

@ -145,13 +145,17 @@ SELECT
INNER JOIN modules m ON l.module_id = m.id
WHERE
m.course_id = c.id) AS lesson_count,
-- Practices whose parent is the course only (lms_practices.course_id). Excludes
-- practices linked via module_id or lesson_id, even for modules/lessons in this course.
(
SELECT
COUNT(*)::bigint
FROM
lms_practices p
WHERE
p.course_id = c.id) AS practice_count
p.course_id = c.id
AND p.module_id IS NULL
AND p.lesson_id IS NULL) AS practice_count
FROM
courses c
WHERE

View File

@ -23,7 +23,8 @@ type Course struct {
SortOrder int `json:"sort_order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
// Populated on list-by-program; practices with course_id set (direct course practice only).
// Populated on list-by-program. Practice count: lms_practices rows with course_id = course only
// (not practices attached to a module or lesson under this course).
ModuleCount int `json:"module_count"`
LessonCount int `json:"lesson_count"`
PracticeCount int `json:"practice_count"`