feat: attach exam prep practices to catalog courses and units
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>
This commit is contained in:
parent
cbbde85e65
commit
208c653e02
16
db/migrations/000093_exam_prep_practice_parents.down.sql
Normal file
16
db/migrations/000093_exam_prep_practice_parents.down.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ALTER TABLE exam_prep.lesson_practices
|
||||
ADD COLUMN unit_module_lesson_id BIGINT REFERENCES exam_prep.unit_module_lessons (id) ON DELETE CASCADE;
|
||||
|
||||
UPDATE exam_prep.lesson_practices lp
|
||||
SET unit_module_lesson_id = pp.parent_id
|
||||
FROM exam_prep.practice_parents pp
|
||||
WHERE pp.practice_id = lp.id
|
||||
AND pp.parent_kind = 'LESSON';
|
||||
|
||||
ALTER TABLE exam_prep.lesson_practices
|
||||
ALTER COLUMN unit_module_lesson_id SET NOT NULL;
|
||||
|
||||
CREATE INDEX idx_exam_prep_lesson_practices_lesson_id ON exam_prep.lesson_practices (unit_module_lesson_id);
|
||||
CREATE INDEX idx_exam_prep_lesson_practices_lesson_created ON exam_prep.lesson_practices (unit_module_lesson_id, created_at DESC);
|
||||
|
||||
DROP TABLE IF EXISTS exam_prep.practice_parents;
|
||||
26
db/migrations/000093_exam_prep_practice_parents.up.sql
Normal file
26
db/migrations/000093_exam_prep_practice_parents.up.sql
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
-- Exam-prep practices can attach to catalog courses, units, or lessons (one parent per practice).
|
||||
CREATE TABLE exam_prep.practice_parents (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
practice_id BIGINT NOT NULL REFERENCES exam_prep.lesson_practices (id) ON DELETE CASCADE,
|
||||
parent_kind VARCHAR(30) NOT NULL CHECK (parent_kind IN ('CATALOG_COURSE', 'UNIT', 'LESSON')),
|
||||
parent_id BIGINT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE (practice_id, parent_kind, parent_id),
|
||||
UNIQUE (parent_kind, parent_id)
|
||||
);
|
||||
|
||||
INSERT INTO exam_prep.practice_parents (practice_id, parent_kind, parent_id)
|
||||
SELECT
|
||||
id,
|
||||
'LESSON',
|
||||
unit_module_lesson_id
|
||||
FROM exam_prep.lesson_practices;
|
||||
|
||||
DROP INDEX IF EXISTS idx_exam_prep_lesson_practices_lesson_id;
|
||||
DROP INDEX IF EXISTS idx_exam_prep_lesson_practices_lesson_created;
|
||||
|
||||
ALTER TABLE exam_prep.lesson_practices
|
||||
DROP COLUMN unit_module_lesson_id;
|
||||
|
||||
CREATE INDEX idx_exam_prep_practice_parents_practice_id ON exam_prep.practice_parents (practice_id);
|
||||
CREATE INDEX idx_exam_prep_practice_parents_lookup ON exam_prep.practice_parents (parent_kind, parent_id);
|
||||
|
|
@ -2,12 +2,21 @@
|
|||
|
||||
-- name: ListUserExamPrepFlatLearningActivityByUser :many
|
||||
SELECT
|
||||
cc.id AS catalog_course_id,
|
||||
cc.name AS catalog_course_name,
|
||||
cc.sort_order AS catalog_course_sort_order,
|
||||
u.id AS unit_id,
|
||||
u.name AS unit_name,
|
||||
u.sort_order AS unit_sort_order,
|
||||
COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id) AS catalog_course_id,
|
||||
COALESCE(cc_direct.name, cc_unit.name, cc_lesson.name) AS catalog_course_name,
|
||||
COALESCE(cc_direct.sort_order, cc_unit.sort_order, cc_lesson.sort_order) AS catalog_course_sort_order,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::bigint
|
||||
ELSE COALESCE(u_direct.id, u_lesson.id)
|
||||
END AS unit_id,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::text
|
||||
ELSE COALESCE(u_direct.name, u_lesson.name)
|
||||
END AS unit_name,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::int
|
||||
ELSE COALESCE(u_direct.sort_order, u_lesson.sort_order)
|
||||
END AS unit_sort_order,
|
||||
m.id AS module_id,
|
||||
m.name AS module_name,
|
||||
m.sort_order AS module_sort_order,
|
||||
|
|
@ -24,22 +33,33 @@ FROM
|
|||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.catalog_courses cc ON cc.id = u.catalog_course_id
|
||||
AND cc.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.units u_lesson ON m.unit_id = u_lesson.id
|
||||
AND u_lesson.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_lesson ON u_lesson.catalog_course_id = cc_lesson.id
|
||||
AND cc_lesson.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.units u_direct ON pp.parent_kind = 'UNIT'
|
||||
AND u_direct.id = pp.parent_id
|
||||
AND u_direct.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_unit ON u_direct.catalog_course_id = cc_unit.id
|
||||
AND cc_unit.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_direct ON pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND cc_direct.id = pp.parent_id
|
||||
AND cc_direct.publish_status = 'PUBLISHED'
|
||||
WHERE
|
||||
upp.user_id = $1
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id) IS NOT NULL
|
||||
ORDER BY
|
||||
cc.sort_order,
|
||||
cc.id,
|
||||
u.sort_order,
|
||||
u.id,
|
||||
COALESCE(cc_direct.sort_order, cc_unit.sort_order, cc_lesson.sort_order),
|
||||
COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id),
|
||||
COALESCE(u_direct.sort_order, u_lesson.sort_order),
|
||||
COALESCE(u_direct.id, u_lesson.id),
|
||||
m.sort_order,
|
||||
m.id,
|
||||
l.sort_order,
|
||||
|
|
|
|||
|
|
@ -20,14 +20,38 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE u.catalog_course_id = c.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = c.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice
|
||||
FROM exam_prep.catalog_courses c
|
||||
WHERE c.id = $1;
|
||||
|
|
@ -63,14 +87,38 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE u.catalog_course_id = c.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = c.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice,
|
||||
c.created_at,
|
||||
c.updated_at
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
-- name: ExamPrepCreateLessonPractice :one
|
||||
-- name: ExamPrepCreatePractice :one
|
||||
INSERT INTO exam_prep.lesson_practices (
|
||||
unit_module_lesson_id,
|
||||
title,
|
||||
story_description,
|
||||
story_image,
|
||||
|
|
@ -8,7 +7,7 @@ INSERT INTO exam_prep.lesson_practices (
|
|||
question_set_id,
|
||||
quick_tips,
|
||||
publish_status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ExamPrepGetLessonPracticeByID :one
|
||||
|
|
@ -23,11 +22,10 @@ WHERE question_set_id = $1
|
|||
ORDER BY id DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: ExamPrepListLessonPracticesByLessonID :many
|
||||
-- name: ExamPrepListPracticesByParent :many
|
||||
SELECT
|
||||
COUNT(*) OVER () AS total_count,
|
||||
p.id,
|
||||
p.unit_module_lesson_id,
|
||||
p.title,
|
||||
p.story_description,
|
||||
p.story_image,
|
||||
|
|
@ -38,14 +36,16 @@ SELECT
|
|||
p.created_at,
|
||||
p.updated_at
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = $1
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = sqlc.arg('parent_kind')::varchar
|
||||
AND pp.parent_id = sqlc.arg('parent_id')::bigint
|
||||
AND (
|
||||
sqlc.arg('published_only')::boolean = FALSE
|
||||
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||
)
|
||||
ORDER BY p.created_at DESC
|
||||
LIMIT $2
|
||||
OFFSET $3;
|
||||
LIMIT $1
|
||||
OFFSET $2;
|
||||
|
||||
-- name: ExamPrepUpdateLessonPractice :one
|
||||
UPDATE exam_prep.lesson_practices
|
||||
|
|
|
|||
43
db/query/exam_prep_practice_parents.sql
Normal file
43
db/query/exam_prep_practice_parents.sql
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
-- name: InsertExamPrepPracticeParent :one
|
||||
INSERT INTO exam_prep.practice_parents (practice_id, parent_kind, parent_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteExamPrepPracticeParentsByPracticeID :exec
|
||||
DELETE FROM exam_prep.practice_parents
|
||||
WHERE practice_id = $1;
|
||||
|
||||
-- name: ListExamPrepPracticeParentsByPracticeID :many
|
||||
SELECT *
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE practice_id = $1
|
||||
ORDER BY id ASC;
|
||||
|
||||
-- name: ListExamPrepPracticeParentsByPracticeIDs :many
|
||||
SELECT *
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE practice_id = ANY (sqlc.arg('practice_ids')::bigint[])
|
||||
ORDER BY practice_id ASC, id ASC;
|
||||
|
||||
-- name: CountExamPrepPracticesByParent :one
|
||||
SELECT COUNT(*)::bigint
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE parent_kind = $1
|
||||
AND parent_id = $2;
|
||||
|
||||
-- name: CountExamPrepPracticesByParentExcludingPractice :one
|
||||
SELECT COUNT(*)::bigint
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE parent_kind = $1
|
||||
AND parent_id = $2
|
||||
AND practice_id <> $3;
|
||||
|
||||
-- name: ListExamPrepPracticeParentsByQuestionSetID :many
|
||||
SELECT
|
||||
pp.parent_kind,
|
||||
pp.parent_id,
|
||||
pp.practice_id
|
||||
FROM exam_prep.practice_parents pp
|
||||
INNER JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||
WHERE p.question_set_id = $1
|
||||
ORDER BY p.id DESC, pp.id ASC;
|
||||
|
|
@ -3,9 +3,11 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
p.unit_module_lesson_id = $1
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
|
|
@ -15,10 +17,74 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
p.unit_module_lesson_id = $1
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
|
||||
-- name: CountPublishedDirectExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
|
||||
-- name: CountUserCompletedPublishedDirectExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
|
||||
-- name: CountPublishedDirectExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
|
||||
-- name: CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
|
|
@ -30,7 +96,9 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
l.unit_module_id = $1
|
||||
|
|
@ -44,7 +112,9 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
|
|
@ -58,77 +128,147 @@ WHERE
|
|||
|
||||
-- name: CountPublishedExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
WHERE
|
||||
m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
);
|
||||
|
||||
-- name: CountUserCompletedPublishedExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
WHERE
|
||||
m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND upp.user_id = $2
|
||||
upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
);
|
||||
|
||||
-- name: CountPublishedExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
-- name: CountUserCompletedPublishedExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
AND upp.user_id = $2
|
||||
upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED';
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
-- name: GetPreviousExamPrepCatalogCourse :one
|
||||
-- Immediate predecessor by sort_order within the same category (gaps in sort_order are allowed).
|
||||
|
|
@ -258,11 +398,13 @@ LIMIT 1;
|
|||
WITH target AS (
|
||||
SELECT
|
||||
lp.id,
|
||||
lp.unit_module_lesson_id,
|
||||
pp.parent_kind,
|
||||
pp.parent_id,
|
||||
lp.created_at,
|
||||
lp.question_set_id
|
||||
FROM
|
||||
exam_prep.lesson_practices lp
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = lp.id
|
||||
INNER JOIN question_sets qs ON qs.id = lp.question_set_id
|
||||
WHERE
|
||||
lp.question_set_id = @question_set_id::BIGINT
|
||||
|
|
@ -278,8 +420,10 @@ candidates AS (
|
|||
lp.created_at
|
||||
FROM
|
||||
exam_prep.lesson_practices lp
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = lp.id
|
||||
INNER JOIN question_sets qs ON qs.id = lp.question_set_id
|
||||
INNER JOIN target t ON lp.unit_module_lesson_id = t.unit_module_lesson_id
|
||||
INNER JOIN target t ON pp.parent_kind = t.parent_kind
|
||||
AND pp.parent_id = t.parent_id
|
||||
WHERE
|
||||
lp.publish_status = 'PUBLISHED'
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = l.id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
) AS has_practice
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
|
|
@ -64,7 +66,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = l.id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
) AS has_practice,
|
||||
l.created_at,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
WHERE l.unit_module_id = m.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
|
|
@ -60,7 +62,9 @@ WITH module_counts AS (
|
|||
FROM exam_prep.unit_modules m
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
|
||||
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
GROUP BY m.id
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,12 +23,26 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
WHERE m.unit_id = u.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = u.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND m.unit_id = u.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = $1;
|
||||
|
|
@ -59,14 +73,35 @@ WITH unit_counts AS (
|
|||
u.id AS unit_id,
|
||||
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
|
||||
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
|
||||
COUNT(DISTINCT p.id)::BIGINT AS practices_count
|
||||
(
|
||||
SELECT COUNT(DISTINCT p.id)::BIGINT
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = u.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l2
|
||||
INNER JOIN exam_prep.unit_modules m2 ON m2.id = l2.unit_module_id
|
||||
WHERE l2.id = pp.parent_id
|
||||
AND m2.unit_id = u.id
|
||||
AND l2.publish_status = 'PUBLISHED'
|
||||
AND m2.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS practices_count
|
||||
FROM exam_prep.units u
|
||||
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
GROUP BY u.id
|
||||
)
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -61,7 +61,13 @@ WITH matched AS (
|
|||
p.persona_id,
|
||||
p.quick_tips,
|
||||
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.updated_at,
|
||||
(
|
||||
|
|
|
|||
|
|
@ -14,12 +14,21 @@ import (
|
|||
const ListUserExamPrepFlatLearningActivityByUser = `-- name: ListUserExamPrepFlatLearningActivityByUser :many
|
||||
|
||||
SELECT
|
||||
cc.id AS catalog_course_id,
|
||||
cc.name AS catalog_course_name,
|
||||
cc.sort_order AS catalog_course_sort_order,
|
||||
u.id AS unit_id,
|
||||
u.name AS unit_name,
|
||||
u.sort_order AS unit_sort_order,
|
||||
COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id) AS catalog_course_id,
|
||||
COALESCE(cc_direct.name, cc_unit.name, cc_lesson.name) AS catalog_course_name,
|
||||
COALESCE(cc_direct.sort_order, cc_unit.sort_order, cc_lesson.sort_order) AS catalog_course_sort_order,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::bigint
|
||||
ELSE COALESCE(u_direct.id, u_lesson.id)
|
||||
END AS unit_id,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::text
|
||||
ELSE COALESCE(u_direct.name, u_lesson.name)
|
||||
END AS unit_name,
|
||||
CASE
|
||||
WHEN pp.parent_kind = 'CATALOG_COURSE' THEN NULL::int
|
||||
ELSE COALESCE(u_direct.sort_order, u_lesson.sort_order)
|
||||
END AS unit_sort_order,
|
||||
m.id AS module_id,
|
||||
m.name AS module_name,
|
||||
m.sort_order AS module_sort_order,
|
||||
|
|
@ -36,22 +45,33 @@ FROM
|
|||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.catalog_courses cc ON cc.id = u.catalog_course_id
|
||||
AND cc.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.units u_lesson ON m.unit_id = u_lesson.id
|
||||
AND u_lesson.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_lesson ON u_lesson.catalog_course_id = cc_lesson.id
|
||||
AND cc_lesson.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.units u_direct ON pp.parent_kind = 'UNIT'
|
||||
AND u_direct.id = pp.parent_id
|
||||
AND u_direct.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_unit ON u_direct.catalog_course_id = cc_unit.id
|
||||
AND cc_unit.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.catalog_courses cc_direct ON pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND cc_direct.id = pp.parent_id
|
||||
AND cc_direct.publish_status = 'PUBLISHED'
|
||||
WHERE
|
||||
upp.user_id = $1
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id) IS NOT NULL
|
||||
ORDER BY
|
||||
cc.sort_order,
|
||||
cc.id,
|
||||
u.sort_order,
|
||||
u.id,
|
||||
COALESCE(cc_direct.sort_order, cc_unit.sort_order, cc_lesson.sort_order),
|
||||
COALESCE(cc_direct.id, cc_unit.id, cc_lesson.id),
|
||||
COALESCE(u_direct.sort_order, u_lesson.sort_order),
|
||||
COALESCE(u_direct.id, u_lesson.id),
|
||||
m.sort_order,
|
||||
m.id,
|
||||
l.sort_order,
|
||||
|
|
@ -63,15 +83,15 @@ type ListUserExamPrepFlatLearningActivityByUserRow struct {
|
|||
CatalogCourseID int64 `json:"catalog_course_id"`
|
||||
CatalogCourseName string `json:"catalog_course_name"`
|
||||
CatalogCourseSortOrder int32 `json:"catalog_course_sort_order"`
|
||||
UnitID int64 `json:"unit_id"`
|
||||
UnitName string `json:"unit_name"`
|
||||
UnitSortOrder int32 `json:"unit_sort_order"`
|
||||
ModuleID int64 `json:"module_id"`
|
||||
ModuleName string `json:"module_name"`
|
||||
ModuleSortOrder int32 `json:"module_sort_order"`
|
||||
LessonID int64 `json:"lesson_id"`
|
||||
LessonTitle string `json:"lesson_title"`
|
||||
LessonSortOrder int32 `json:"lesson_sort_order"`
|
||||
UnitID interface{} `json:"unit_id"`
|
||||
UnitName interface{} `json:"unit_name"`
|
||||
UnitSortOrder interface{} `json:"unit_sort_order"`
|
||||
ModuleID pgtype.Int8 `json:"module_id"`
|
||||
ModuleName pgtype.Text `json:"module_name"`
|
||||
ModuleSortOrder pgtype.Int4 `json:"module_sort_order"`
|
||||
LessonID pgtype.Int8 `json:"lesson_id"`
|
||||
LessonTitle pgtype.Text `json:"lesson_title"`
|
||||
LessonSortOrder pgtype.Int4 `json:"lesson_sort_order"`
|
||||
ExamPrepPracticeID int64 `json:"exam_prep_practice_id"`
|
||||
PracticeTitle string `json:"practice_title"`
|
||||
ActivityAt pgtype.Timestamptz `json:"activity_at"`
|
||||
|
|
|
|||
|
|
@ -78,14 +78,38 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE u.catalog_course_id = c.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = c.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice
|
||||
FROM exam_prep.catalog_courses c
|
||||
WHERE c.id = $1
|
||||
|
|
@ -182,14 +206,38 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE u.catalog_course_id = c.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = c.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = c.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice,
|
||||
c.created_at,
|
||||
c.updated_at
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ import (
|
|||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const ExamPrepCreateLessonPractice = `-- name: ExamPrepCreateLessonPractice :one
|
||||
const ExamPrepCreatePractice = `-- name: ExamPrepCreatePractice :one
|
||||
INSERT INTO exam_prep.lesson_practices (
|
||||
unit_module_lesson_id,
|
||||
title,
|
||||
story_description,
|
||||
story_image,
|
||||
|
|
@ -21,24 +20,22 @@ INSERT INTO exam_prep.lesson_practices (
|
|||
question_set_id,
|
||||
quick_tips,
|
||||
publish_status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, unit_module_lesson_id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
`
|
||||
|
||||
type ExamPrepCreateLessonPracticeParams struct {
|
||||
UnitModuleLessonID int64 `json:"unit_module_lesson_id"`
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
type ExamPrepCreatePracticeParams struct {
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
}
|
||||
|
||||
func (q *Queries) ExamPrepCreateLessonPractice(ctx context.Context, arg ExamPrepCreateLessonPracticeParams) (ExamPrepLessonPractice, error) {
|
||||
row := q.db.QueryRow(ctx, ExamPrepCreateLessonPractice,
|
||||
arg.UnitModuleLessonID,
|
||||
func (q *Queries) ExamPrepCreatePractice(ctx context.Context, arg ExamPrepCreatePracticeParams) (ExamPrepLessonPractice, error) {
|
||||
row := q.db.QueryRow(ctx, ExamPrepCreatePractice,
|
||||
arg.Title,
|
||||
arg.StoryDescription,
|
||||
arg.StoryImage,
|
||||
|
|
@ -50,7 +47,6 @@ func (q *Queries) ExamPrepCreateLessonPractice(ctx context.Context, arg ExamPrep
|
|||
var i ExamPrepLessonPractice
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UnitModuleLessonID,
|
||||
&i.Title,
|
||||
&i.StoryDescription,
|
||||
&i.StoryImage,
|
||||
|
|
@ -75,7 +71,7 @@ func (q *Queries) ExamPrepDeleteLessonPractice(ctx context.Context, id int64) er
|
|||
}
|
||||
|
||||
const ExamPrepGetLessonPracticeByID = `-- name: ExamPrepGetLessonPracticeByID :one
|
||||
SELECT id, unit_module_lesson_id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
SELECT id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
FROM exam_prep.lesson_practices
|
||||
WHERE id = $1
|
||||
`
|
||||
|
|
@ -85,7 +81,6 @@ func (q *Queries) ExamPrepGetLessonPracticeByID(ctx context.Context, id int64) (
|
|||
var i ExamPrepLessonPractice
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UnitModuleLessonID,
|
||||
&i.Title,
|
||||
&i.StoryDescription,
|
||||
&i.StoryImage,
|
||||
|
|
@ -100,7 +95,7 @@ func (q *Queries) ExamPrepGetLessonPracticeByID(ctx context.Context, id int64) (
|
|||
}
|
||||
|
||||
const ExamPrepGetLessonPracticeByQuestionSetID = `-- name: ExamPrepGetLessonPracticeByQuestionSetID :one
|
||||
SELECT id, unit_module_lesson_id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
SELECT id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
FROM exam_prep.lesson_practices
|
||||
WHERE question_set_id = $1
|
||||
ORDER BY id DESC
|
||||
|
|
@ -112,7 +107,6 @@ func (q *Queries) ExamPrepGetLessonPracticeByQuestionSetID(ctx context.Context,
|
|||
var i ExamPrepLessonPractice
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UnitModuleLessonID,
|
||||
&i.Title,
|
||||
&i.StoryDescription,
|
||||
&i.StoryImage,
|
||||
|
|
@ -126,11 +120,10 @@ func (q *Queries) ExamPrepGetLessonPracticeByQuestionSetID(ctx context.Context,
|
|||
return i, err
|
||||
}
|
||||
|
||||
const ExamPrepListLessonPracticesByLessonID = `-- name: ExamPrepListLessonPracticesByLessonID :many
|
||||
const ExamPrepListPracticesByParent = `-- name: ExamPrepListPracticesByParent :many
|
||||
SELECT
|
||||
COUNT(*) OVER () AS total_count,
|
||||
p.id,
|
||||
p.unit_module_lesson_id,
|
||||
p.title,
|
||||
p.story_description,
|
||||
p.story_image,
|
||||
|
|
@ -141,56 +134,58 @@ SELECT
|
|||
p.created_at,
|
||||
p.updated_at
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = $1
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = $3::varchar
|
||||
AND pp.parent_id = $4::bigint
|
||||
AND (
|
||||
$4::boolean = FALSE
|
||||
$5::boolean = FALSE
|
||||
OR p.publish_status = 'PUBLISHED'::TEXT
|
||||
)
|
||||
ORDER BY p.created_at DESC
|
||||
LIMIT $2
|
||||
OFFSET $3
|
||||
LIMIT $1
|
||||
OFFSET $2
|
||||
`
|
||||
|
||||
type ExamPrepListLessonPracticesByLessonIDParams struct {
|
||||
UnitModuleLessonID int64 `json:"unit_module_lesson_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
PublishedOnly bool `json:"published_only"`
|
||||
type ExamPrepListPracticesByParentParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
PublishedOnly bool `json:"published_only"`
|
||||
}
|
||||
|
||||
type ExamPrepListLessonPracticesByLessonIDRow struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
ID int64 `json:"id"`
|
||||
UnitModuleLessonID int64 `json:"unit_module_lesson_id"`
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
type ExamPrepListPracticesByParentRow struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ExamPrepListLessonPracticesByLessonID(ctx context.Context, arg ExamPrepListLessonPracticesByLessonIDParams) ([]ExamPrepListLessonPracticesByLessonIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, ExamPrepListLessonPracticesByLessonID,
|
||||
arg.UnitModuleLessonID,
|
||||
func (q *Queries) ExamPrepListPracticesByParent(ctx context.Context, arg ExamPrepListPracticesByParentParams) ([]ExamPrepListPracticesByParentRow, error) {
|
||||
rows, err := q.db.Query(ctx, ExamPrepListPracticesByParent,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
arg.ParentKind,
|
||||
arg.ParentID,
|
||||
arg.PublishedOnly,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ExamPrepListLessonPracticesByLessonIDRow
|
||||
var items []ExamPrepListPracticesByParentRow
|
||||
for rows.Next() {
|
||||
var i ExamPrepListLessonPracticesByLessonIDRow
|
||||
var i ExamPrepListPracticesByParentRow
|
||||
if err := rows.Scan(
|
||||
&i.TotalCount,
|
||||
&i.ID,
|
||||
&i.UnitModuleLessonID,
|
||||
&i.Title,
|
||||
&i.StoryDescription,
|
||||
&i.StoryImage,
|
||||
|
|
@ -223,7 +218,7 @@ SET
|
|||
publish_status = coalesce($7::varchar, publish_status),
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $8
|
||||
RETURNING id, unit_module_lesson_id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
RETURNING id, title, story_description, story_image, persona_id, question_set_id, quick_tips, created_at, updated_at, publish_status
|
||||
`
|
||||
|
||||
type ExamPrepUpdateLessonPracticeParams struct {
|
||||
|
|
@ -251,7 +246,6 @@ func (q *Queries) ExamPrepUpdateLessonPractice(ctx context.Context, arg ExamPrep
|
|||
var i ExamPrepLessonPractice
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UnitModuleLessonID,
|
||||
&i.Title,
|
||||
&i.StoryDescription,
|
||||
&i.StoryImage,
|
||||
|
|
|
|||
188
gen/db/exam_prep_practice_parents.sql.go
Normal file
188
gen/db/exam_prep_practice_parents.sql.go
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: exam_prep_practice_parents.sql
|
||||
|
||||
package dbgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const CountExamPrepPracticesByParent = `-- name: CountExamPrepPracticesByParent :one
|
||||
SELECT COUNT(*)::bigint
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE parent_kind = $1
|
||||
AND parent_id = $2
|
||||
`
|
||||
|
||||
type CountExamPrepPracticesByParentParams struct {
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountExamPrepPracticesByParent(ctx context.Context, arg CountExamPrepPracticesByParentParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountExamPrepPracticesByParent, arg.ParentKind, arg.ParentID)
|
||||
var column_1 int64
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
||||
|
||||
const CountExamPrepPracticesByParentExcludingPractice = `-- name: CountExamPrepPracticesByParentExcludingPractice :one
|
||||
SELECT COUNT(*)::bigint
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE parent_kind = $1
|
||||
AND parent_id = $2
|
||||
AND practice_id <> $3
|
||||
`
|
||||
|
||||
type CountExamPrepPracticesByParentExcludingPracticeParams struct {
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
PracticeID int64 `json:"practice_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountExamPrepPracticesByParentExcludingPractice(ctx context.Context, arg CountExamPrepPracticesByParentExcludingPracticeParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountExamPrepPracticesByParentExcludingPractice, arg.ParentKind, arg.ParentID, arg.PracticeID)
|
||||
var column_1 int64
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
||||
|
||||
const DeleteExamPrepPracticeParentsByPracticeID = `-- name: DeleteExamPrepPracticeParentsByPracticeID :exec
|
||||
DELETE FROM exam_prep.practice_parents
|
||||
WHERE practice_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteExamPrepPracticeParentsByPracticeID(ctx context.Context, practiceID int64) error {
|
||||
_, err := q.db.Exec(ctx, DeleteExamPrepPracticeParentsByPracticeID, practiceID)
|
||||
return err
|
||||
}
|
||||
|
||||
const InsertExamPrepPracticeParent = `-- name: InsertExamPrepPracticeParent :one
|
||||
INSERT INTO exam_prep.practice_parents (practice_id, parent_kind, parent_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, practice_id, parent_kind, parent_id, created_at
|
||||
`
|
||||
|
||||
type InsertExamPrepPracticeParentParams struct {
|
||||
PracticeID int64 `json:"practice_id"`
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertExamPrepPracticeParent(ctx context.Context, arg InsertExamPrepPracticeParentParams) (ExamPrepPracticeParent, error) {
|
||||
row := q.db.QueryRow(ctx, InsertExamPrepPracticeParent, arg.PracticeID, arg.ParentKind, arg.ParentID)
|
||||
var i ExamPrepPracticeParent
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PracticeID,
|
||||
&i.ParentKind,
|
||||
&i.ParentID,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const ListExamPrepPracticeParentsByPracticeID = `-- name: ListExamPrepPracticeParentsByPracticeID :many
|
||||
SELECT id, practice_id, parent_kind, parent_id, created_at
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE practice_id = $1
|
||||
ORDER BY id ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListExamPrepPracticeParentsByPracticeID(ctx context.Context, practiceID int64) ([]ExamPrepPracticeParent, error) {
|
||||
rows, err := q.db.Query(ctx, ListExamPrepPracticeParentsByPracticeID, practiceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ExamPrepPracticeParent
|
||||
for rows.Next() {
|
||||
var i ExamPrepPracticeParent
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.PracticeID,
|
||||
&i.ParentKind,
|
||||
&i.ParentID,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const ListExamPrepPracticeParentsByPracticeIDs = `-- name: ListExamPrepPracticeParentsByPracticeIDs :many
|
||||
SELECT id, practice_id, parent_kind, parent_id, created_at
|
||||
FROM exam_prep.practice_parents
|
||||
WHERE practice_id = ANY ($1::bigint[])
|
||||
ORDER BY practice_id ASC, id ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListExamPrepPracticeParentsByPracticeIDs(ctx context.Context, practiceIds []int64) ([]ExamPrepPracticeParent, error) {
|
||||
rows, err := q.db.Query(ctx, ListExamPrepPracticeParentsByPracticeIDs, practiceIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ExamPrepPracticeParent
|
||||
for rows.Next() {
|
||||
var i ExamPrepPracticeParent
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.PracticeID,
|
||||
&i.ParentKind,
|
||||
&i.ParentID,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const ListExamPrepPracticeParentsByQuestionSetID = `-- name: ListExamPrepPracticeParentsByQuestionSetID :many
|
||||
SELECT
|
||||
pp.parent_kind,
|
||||
pp.parent_id,
|
||||
pp.practice_id
|
||||
FROM exam_prep.practice_parents pp
|
||||
INNER JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||
WHERE p.question_set_id = $1
|
||||
ORDER BY p.id DESC, pp.id ASC
|
||||
`
|
||||
|
||||
type ListExamPrepPracticeParentsByQuestionSetIDRow struct {
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
PracticeID int64 `json:"practice_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListExamPrepPracticeParentsByQuestionSetID(ctx context.Context, questionSetID int64) ([]ListExamPrepPracticeParentsByQuestionSetIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, ListExamPrepPracticeParentsByQuestionSetID, questionSetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListExamPrepPracticeParentsByQuestionSetIDRow
|
||||
for rows.Next() {
|
||||
var i ListExamPrepPracticeParentsByQuestionSetIDRow
|
||||
if err := rows.Scan(&i.ParentKind, &i.ParentID, &i.PracticeID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
|
@ -11,27 +11,95 @@ import (
|
|||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const CountPublishedExamPrepPracticesInCatalogCourse = `-- name: CountPublishedExamPrepPracticesInCatalogCourse :one
|
||||
const CountPublishedDirectExamPrepPracticesInCatalogCourse = `-- name: CountPublishedDirectExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
`
|
||||
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInCatalogCourse(ctx context.Context, catalogCourseID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInCatalogCourse, catalogCourseID)
|
||||
func (q *Queries) CountPublishedDirectExamPrepPracticesInCatalogCourse(ctx context.Context, parentID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedDirectExamPrepPracticesInCatalogCourse, parentID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
const CountPublishedDirectExamPrepPracticesInUnit = `-- name: CountPublishedDirectExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
`
|
||||
|
||||
func (q *Queries) CountPublishedDirectExamPrepPracticesInUnit(ctx context.Context, parentID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedDirectExamPrepPracticesInUnit, parentID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
const CountPublishedExamPrepPracticesInCatalogCourse = `-- name: CountPublishedExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInCatalogCourse(ctx context.Context, parentID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInCatalogCourse, parentID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
|
|
@ -42,16 +110,18 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
p.unit_module_lesson_id = $1
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = $1
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
`
|
||||
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInLesson(ctx context.Context, unitModuleLessonID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInLesson, unitModuleLessonID)
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInLesson(ctx context.Context, parentID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInLesson, parentID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
|
|
@ -62,7 +132,9 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
WHERE
|
||||
l.unit_module_id = $1
|
||||
|
|
@ -81,43 +153,50 @@ func (q *Queries) CountPublishedExamPrepPracticesInModule(ctx context.Context, u
|
|||
|
||||
const CountPublishedExamPrepPracticesInUnit = `-- name: CountPublishedExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
WHERE
|
||||
m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInUnit(ctx context.Context, unitID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInUnit, unitID)
|
||||
func (q *Queries) CountPublishedExamPrepPracticesInUnit(ctx context.Context, parentID int64) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInUnit, parentID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
const CountUserCompletedPublishedExamPrepPracticesInCatalogCourse = `-- name: CountUserCompletedPublishedExamPrepPracticesInCatalogCourse :one
|
||||
const CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse = `-- name: CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
|
|
@ -125,13 +204,101 @@ WHERE
|
|||
AND p.publish_status = 'PUBLISHED'
|
||||
`
|
||||
|
||||
type CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourseParams struct {
|
||||
ParentID int64 `json:"parent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse(ctx context.Context, arg CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourseParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse, arg.ParentID, arg.UserID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
const CountUserCompletedPublishedDirectExamPrepPracticesInUnit = `-- name: CountUserCompletedPublishedDirectExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
`
|
||||
|
||||
type CountUserCompletedPublishedDirectExamPrepPracticesInUnitParams struct {
|
||||
ParentID int64 `json:"parent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUserCompletedPublishedDirectExamPrepPracticesInUnit(ctx context.Context, arg CountUserCompletedPublishedDirectExamPrepPracticesInUnitParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedDirectExamPrepPracticesInUnit, arg.ParentID, arg.UserID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
const CountUserCompletedPublishedExamPrepPracticesInCatalogCourse = `-- name: CountUserCompletedPublishedExamPrepPracticesInCatalogCourse :one
|
||||
SELECT
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'CATALOG_COURSE'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.units u ON u.id = m.unit_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND u.catalog_course_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND u.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
type CountUserCompletedPublishedExamPrepPracticesInCatalogCourseParams struct {
|
||||
CatalogCourseID int64 `json:"catalog_course_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUserCompletedPublishedExamPrepPracticesInCatalogCourse(ctx context.Context, arg CountUserCompletedPublishedExamPrepPracticesInCatalogCourseParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInCatalogCourse, arg.CatalogCourseID, arg.UserID)
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInCatalogCourse, arg.ParentID, arg.UserID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
|
|
@ -142,10 +309,12 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
p.unit_module_lesson_id = $1
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = $1
|
||||
AND upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
|
|
@ -154,12 +323,12 @@ WHERE
|
|||
`
|
||||
|
||||
type CountUserCompletedPublishedExamPrepPracticesInLessonParams struct {
|
||||
UnitModuleLessonID int64 `json:"unit_module_lesson_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUserCompletedPublishedExamPrepPracticesInLesson(ctx context.Context, arg CountUserCompletedPublishedExamPrepPracticesInLessonParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInLesson, arg.UnitModuleLessonID, arg.UserID)
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInLesson, arg.ParentID, arg.UserID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
|
|
@ -170,7 +339,9 @@ SELECT
|
|||
count(*)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
WHERE
|
||||
|
|
@ -197,31 +368,42 @@ func (q *Queries) CountUserCompletedPublishedExamPrepPracticesInModule(ctx conte
|
|||
|
||||
const CountUserCompletedPublishedExamPrepPracticesInUnit = `-- name: CountUserCompletedPublishedExamPrepPracticesInUnit :one
|
||||
SELECT
|
||||
count(*)::int AS n
|
||||
count(DISTINCT p.id)::int AS n
|
||||
FROM
|
||||
exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN question_sets qs ON qs.id = p.question_set_id
|
||||
INNER JOIN user_practice_progress upp ON upp.question_set_id = p.question_set_id
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
LEFT JOIN exam_prep.unit_modules m ON l.unit_module_id = m.id
|
||||
WHERE
|
||||
m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
AND upp.user_id = $2
|
||||
upp.user_id = $2
|
||||
AND upp.completed_at IS NOT NULL
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
AND qs.status = 'PUBLISHED'
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = $1
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND m.unit_id = $1
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
type CountUserCompletedPublishedExamPrepPracticesInUnitParams struct {
|
||||
UnitID int64 `json:"unit_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUserCompletedPublishedExamPrepPracticesInUnit(ctx context.Context, arg CountUserCompletedPublishedExamPrepPracticesInUnitParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInUnit, arg.UnitID, arg.UserID)
|
||||
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInUnit, arg.ParentID, arg.UserID)
|
||||
var n int32
|
||||
err := row.Scan(&n)
|
||||
return n, err
|
||||
|
|
@ -231,11 +413,13 @@ const GetFirstIncompletePreviousExamPrepPractice = `-- name: GetFirstIncompleteP
|
|||
WITH target AS (
|
||||
SELECT
|
||||
lp.id,
|
||||
lp.unit_module_lesson_id,
|
||||
pp.parent_kind,
|
||||
pp.parent_id,
|
||||
lp.created_at,
|
||||
lp.question_set_id
|
||||
FROM
|
||||
exam_prep.lesson_practices lp
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = lp.id
|
||||
INNER JOIN question_sets qs ON qs.id = lp.question_set_id
|
||||
WHERE
|
||||
lp.question_set_id = $2::BIGINT
|
||||
|
|
@ -251,8 +435,10 @@ candidates AS (
|
|||
lp.created_at
|
||||
FROM
|
||||
exam_prep.lesson_practices lp
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = lp.id
|
||||
INNER JOIN question_sets qs ON qs.id = lp.question_set_id
|
||||
INNER JOIN target t ON lp.unit_module_lesson_id = t.unit_module_lesson_id
|
||||
INNER JOIN target t ON pp.parent_kind = t.parent_kind
|
||||
AND pp.parent_id = t.parent_id
|
||||
WHERE
|
||||
lp.publish_status = 'PUBLISHED'
|
||||
AND qs.set_type = 'PRACTICE'
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = l.id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
) AS has_practice
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
|
|
@ -203,7 +205,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
WHERE p.unit_module_lesson_id = l.id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
) AS has_practice,
|
||||
l.created_at,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON pp.parent_kind = 'LESSON'
|
||||
AND l.id = pp.parent_id
|
||||
WHERE l.unit_module_id = m.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
|
|
@ -199,7 +201,9 @@ WITH module_counts AS (
|
|||
FROM exam_prep.unit_modules m
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
|
||||
LEFT JOIN exam_prep.practice_parents pp ON pp.parent_kind = 'LESSON'
|
||||
AND pp.parent_id = l.id
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.id = pp.practice_id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
GROUP BY m.id
|
||||
)
|
||||
|
|
|
|||
|
|
@ -83,12 +83,26 @@ SELECT
|
|||
EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.unit_module_lessons l ON l.id = p.unit_module_lesson_id
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
WHERE m.unit_id = u.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = u.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l
|
||||
INNER JOIN exam_prep.unit_modules m ON m.id = l.unit_module_id
|
||||
WHERE l.id = pp.parent_id
|
||||
AND m.unit_id = u.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS has_practice
|
||||
FROM exam_prep.units u
|
||||
WHERE u.id = $1
|
||||
|
|
@ -195,14 +209,35 @@ WITH unit_counts AS (
|
|||
u.id AS unit_id,
|
||||
COUNT(DISTINCT m.id)::BIGINT AS modules_count,
|
||||
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
|
||||
COUNT(DISTINCT p.id)::BIGINT AS practices_count
|
||||
(
|
||||
SELECT COUNT(DISTINCT p.id)::BIGINT
|
||||
FROM exam_prep.lesson_practices p
|
||||
INNER JOIN exam_prep.practice_parents pp ON pp.practice_id = p.id
|
||||
WHERE p.publish_status = 'PUBLISHED'
|
||||
AND (
|
||||
(
|
||||
pp.parent_kind = 'UNIT'
|
||||
AND pp.parent_id = u.id
|
||||
)
|
||||
OR (
|
||||
pp.parent_kind = 'LESSON'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM exam_prep.unit_module_lessons l2
|
||||
INNER JOIN exam_prep.unit_modules m2 ON m2.id = l2.unit_module_id
|
||||
WHERE l2.id = pp.parent_id
|
||||
AND m2.unit_id = u.id
|
||||
AND l2.publish_status = 'PUBLISHED'
|
||||
AND m2.publish_status = 'PUBLISHED'
|
||||
)
|
||||
)
|
||||
)
|
||||
) AS practices_count
|
||||
FROM exam_prep.units u
|
||||
LEFT JOIN exam_prep.unit_modules m ON m.unit_id = u.id
|
||||
AND m.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
|
||||
AND l.publish_status = 'PUBLISHED'
|
||||
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
|
||||
AND p.publish_status = 'PUBLISHED'
|
||||
GROUP BY u.id
|
||||
)
|
||||
SELECT
|
||||
|
|
|
|||
|
|
@ -73,17 +73,24 @@ type ExamPrepCatalogCourse struct {
|
|||
}
|
||||
|
||||
type ExamPrepLessonPractice struct {
|
||||
ID int64 `json:"id"`
|
||||
UnitModuleLessonID int64 `json:"unit_module_lesson_id"`
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
StoryDescription pgtype.Text `json:"story_description"`
|
||||
StoryImage pgtype.Text `json:"story_image"`
|
||||
PersonaID pgtype.Int8 `json:"persona_id"`
|
||||
QuestionSetID int64 `json:"question_set_id"`
|
||||
QuickTips pgtype.Text `json:"quick_tips"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
}
|
||||
|
||||
type ExamPrepPracticeParent struct {
|
||||
ID int64 `json:"id"`
|
||||
PracticeID int64 `json:"practice_id"`
|
||||
ParentKind string `json:"parent_kind"`
|
||||
ParentID int64 `json:"parent_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type ExamPrepUnit struct {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,13 @@ WITH matched AS (
|
|||
p.persona_id,
|
||||
p.quick_tips,
|
||||
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.updated_at,
|
||||
(
|
||||
|
|
|
|||
|
|
@ -63,16 +63,18 @@ type AdminExamPrepUserLearningActivityTree struct {
|
|||
}
|
||||
|
||||
type AdminExamPrepCatalogCourseLearningEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
Units []AdminExamPrepUnitLearningEntry `json:"units"`
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
Practices []AdminExamPrepPracticeLearningEntry `json:"practices"`
|
||||
Units []AdminExamPrepUnitLearningEntry `json:"units"`
|
||||
}
|
||||
|
||||
type AdminExamPrepUnitLearningEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
Practices []AdminExamPrepPracticeLearningEntry `json:"practices"`
|
||||
Modules []AdminExamPrepModuleLearningEntry `json:"modules"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,61 @@ package domain
|
|||
|
||||
import "time"
|
||||
|
||||
// ExamPrepPractice is question-set content tied to an exam-prep lesson; uses shared question_sets / questions.
|
||||
// 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"`
|
||||
LessonID int64 `json:"lesson_id"` // exam_prep.unit_module_lessons.id
|
||||
Title string `json:"title"`
|
||||
StoryDescription *string `json:"story_description,omitempty"`
|
||||
StoryImage *string `json:"story_image,omitempty"`
|
||||
PersonaID *int64 `json:"persona_id,omitempty"` // lms_personas.id when set
|
||||
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"`
|
||||
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.
|
||||
|
|
@ -22,7 +64,7 @@ func (p ExamPrepPractice) VisibleToLearners() bool {
|
|||
return p.PublishStatus == PracticePublishPublished
|
||||
}
|
||||
|
||||
// CreateExamPrepPracticeInput is the body for POST .../exam-prep/lessons/{lessonId}/practices (lesson from path).
|
||||
// CreateExamPrepPracticeInput is the body for POST .../exam-prep/{parent}/practices.
|
||||
type CreateExamPrepPracticeInput struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
StoryDescription *string `json:"story_description,omitempty"`
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
// ExamPrepPracticeStore persists exam_prep.lesson_practices.
|
||||
// ExamPrepPracticeStore persists exam_prep.lesson_practices and exam_prep.practice_parents.
|
||||
type ExamPrepPracticeStore interface {
|
||||
CreateExamPrepLessonPractice(ctx context.Context, lessonID int64, in domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error)
|
||||
CreateExamPrepPractice(ctx context.Context, parent domain.ExamPrepPracticeParent, in domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error)
|
||||
GetExamPrepLessonPracticeByID(ctx context.Context, id int64) (domain.ExamPrepPractice, error)
|
||||
TryGetExamPrepLessonPracticeByQuestionSetID(ctx context.Context, questionSetID int64) (domain.ExamPrepPractice, bool, error)
|
||||
ListExamPrepLessonPracticesByLessonID(ctx context.Context, lessonID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error)
|
||||
ListExamPrepPracticesByParent(ctx context.Context, parent domain.ExamPrepPracticeParent, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error)
|
||||
CountExamPrepPracticesByParent(ctx context.Context, kind domain.ExamPrepParentKind, parentID int64) (int64, error)
|
||||
CountExamPrepPracticesByParentExcludingPractice(ctx context.Context, kind domain.ExamPrepParentKind, parentID, excludePracticeID int64) (int64, error)
|
||||
UpdateExamPrepLessonPractice(ctx context.Context, id int64, input domain.UpdateExamPrepPracticeInput) (domain.ExamPrepPractice, error)
|
||||
DeleteExamPrepLessonPractice(ctx context.Context, id int64) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package repository
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
dbgen "Yimaru-Backend/gen/db"
|
||||
"Yimaru-Backend/internal/domain"
|
||||
|
|
@ -11,30 +12,36 @@ import (
|
|||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func examPrepPracticeFromListRow(r dbgen.ExamPrepListLessonPracticesByLessonIDRow) domain.ExamPrepPractice {
|
||||
return examPrepPracticeToDomain(dbgen.ExamPrepLessonPractice{
|
||||
ID: r.ID,
|
||||
UnitModuleLessonID: r.UnitModuleLessonID,
|
||||
Title: r.Title,
|
||||
StoryDescription: r.StoryDescription,
|
||||
StoryImage: r.StoryImage,
|
||||
PersonaID: r.PersonaID,
|
||||
QuestionSetID: r.QuestionSetID,
|
||||
QuickTips: r.QuickTips,
|
||||
PublishStatus: r.PublishStatus,
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
})
|
||||
func examPrepPracticeParentFromDB(row dbgen.ExamPrepPracticeParent) domain.ExamPrepPracticeParent {
|
||||
return domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKind(row.ParentKind),
|
||||
ID: row.ParentID,
|
||||
}
|
||||
}
|
||||
|
||||
func examPrepPracticeToDomain(p dbgen.ExamPrepLessonPractice) domain.ExamPrepPractice {
|
||||
func examPrepPracticeParentsFromDB(rows []dbgen.ExamPrepPracticeParent) []domain.ExamPrepPracticeParent {
|
||||
out := make([]domain.ExamPrepPracticeParent, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, examPrepPracticeParentFromDB(row))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func examPrepPracticeToDomain(p dbgen.ExamPrepLessonPractice, parents []domain.ExamPrepPracticeParent) domain.ExamPrepPractice {
|
||||
out := domain.ExamPrepPractice{
|
||||
ID: p.ID,
|
||||
LessonID: p.UnitModuleLessonID,
|
||||
Parents: domain.ExamPrepPracticeParentsPtr(parents),
|
||||
Title: p.Title,
|
||||
QuestionSetID: p.QuestionSetID,
|
||||
PublishStatus: domain.PracticePublishStatusFromDB(p.PublishStatus),
|
||||
}
|
||||
for _, parent := range parents {
|
||||
if parent.Kind == domain.ExamPrepParentKindLesson {
|
||||
id := parent.ID
|
||||
out.LessonID = &id
|
||||
break
|
||||
}
|
||||
}
|
||||
out.StoryDescription = fromPgText(p.StoryDescription)
|
||||
out.StoryImage = fromPgText(p.StoryImage)
|
||||
out.QuickTips = fromPgText(p.QuickTips)
|
||||
|
|
@ -47,22 +54,66 @@ func examPrepPracticeToDomain(p dbgen.ExamPrepLessonPractice) domain.ExamPrepPra
|
|||
return out
|
||||
}
|
||||
|
||||
func (s *Store) CreateExamPrepLessonPractice(ctx context.Context, lessonID int64, in domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
func examPrepPracticeFromListRow(r dbgen.ExamPrepListPracticesByParentRow, parent domain.ExamPrepPracticeParent) domain.ExamPrepPractice {
|
||||
p := dbgen.ExamPrepLessonPractice{
|
||||
ID: r.ID,
|
||||
Title: r.Title,
|
||||
StoryDescription: r.StoryDescription,
|
||||
StoryImage: r.StoryImage,
|
||||
PersonaID: r.PersonaID,
|
||||
QuestionSetID: r.QuestionSetID,
|
||||
QuickTips: r.QuickTips,
|
||||
PublishStatus: r.PublishStatus,
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
}
|
||||
return examPrepPracticeToDomain(p, []domain.ExamPrepPracticeParent{parent})
|
||||
}
|
||||
|
||||
func (s *Store) loadExamPrepPracticeParents(ctx context.Context, practiceID int64) ([]domain.ExamPrepPracticeParent, error) {
|
||||
rows, err := s.queries.ListExamPrepPracticeParentsByPracticeID(ctx, practiceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return examPrepPracticeParentsFromDB(rows), nil
|
||||
}
|
||||
|
||||
func (s *Store) insertExamPrepPracticeParent(ctx context.Context, q *dbgen.Queries, practiceID int64, parent domain.ExamPrepPracticeParent) error {
|
||||
_, err := q.InsertExamPrepPracticeParent(ctx, dbgen.InsertExamPrepPracticeParentParams{
|
||||
PracticeID: practiceID,
|
||||
ParentKind: string(parent.Kind),
|
||||
ParentID: parent.ID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) CreateExamPrepPractice(ctx context.Context, parent domain.ExamPrepPracticeParent, in domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
ps := domain.ParsePracticePublishStatusInput(in.PublishStatus)
|
||||
p, err := s.queries.ExamPrepCreateLessonPractice(ctx, dbgen.ExamPrepCreateLessonPracticeParams{
|
||||
UnitModuleLessonID: lessonID,
|
||||
Title: derefString(in.Title),
|
||||
StoryDescription: toPgText(in.StoryDescription),
|
||||
StoryImage: toPgText(in.StoryImage),
|
||||
PersonaID: int64PtrToPg8(in.PersonaID),
|
||||
QuestionSetID: in.QuestionSetID,
|
||||
QuickTips: toPgText(in.QuickTips),
|
||||
PublishStatus: string(ps),
|
||||
q, tx, err := s.BeginTx(ctx)
|
||||
if err != nil {
|
||||
return domain.ExamPrepPractice{}, fmt.Errorf("begin tx: %w", err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
|
||||
p, err := q.ExamPrepCreatePractice(ctx, dbgen.ExamPrepCreatePracticeParams{
|
||||
Title: derefString(in.Title),
|
||||
StoryDescription: toPgText(in.StoryDescription),
|
||||
StoryImage: toPgText(in.StoryImage),
|
||||
PersonaID: int64PtrToPg8(in.PersonaID),
|
||||
QuestionSetID: in.QuestionSetID,
|
||||
QuickTips: toPgText(in.QuickTips),
|
||||
PublishStatus: string(ps),
|
||||
})
|
||||
if err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p), nil
|
||||
if err := s.insertExamPrepPracticeParent(ctx, q, p.ID, parent); err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return domain.ExamPrepPractice{}, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
return examPrepPracticeToDomain(p, []domain.ExamPrepPracticeParent{parent}), nil
|
||||
}
|
||||
|
||||
func (s *Store) GetExamPrepLessonPracticeByID(ctx context.Context, id int64) (domain.ExamPrepPractice, error) {
|
||||
|
|
@ -73,10 +124,13 @@ func (s *Store) GetExamPrepLessonPracticeByID(ctx context.Context, id int64) (do
|
|||
}
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p), nil
|
||||
parents, err := s.loadExamPrepPracticeParents(ctx, id)
|
||||
if err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p, parents), nil
|
||||
}
|
||||
|
||||
// TryGetExamPrepLessonPracticeByQuestionSetID returns false when no row exists.
|
||||
func (s *Store) TryGetExamPrepLessonPracticeByQuestionSetID(ctx context.Context, questionSetID int64) (domain.ExamPrepPractice, bool, error) {
|
||||
p, err := s.queries.ExamPrepGetLessonPracticeByQuestionSetID(ctx, questionSetID)
|
||||
if err != nil {
|
||||
|
|
@ -85,15 +139,20 @@ func (s *Store) TryGetExamPrepLessonPracticeByQuestionSetID(ctx context.Context,
|
|||
}
|
||||
return domain.ExamPrepPractice{}, false, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p), true, nil
|
||||
parents, err := s.loadExamPrepPracticeParents(ctx, p.ID)
|
||||
if err != nil {
|
||||
return domain.ExamPrepPractice{}, false, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p, parents), true, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListExamPrepLessonPracticesByLessonID(ctx context.Context, lessonID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
rows, err := s.queries.ExamPrepListLessonPracticesByLessonID(ctx, dbgen.ExamPrepListLessonPracticesByLessonIDParams{
|
||||
UnitModuleLessonID: lessonID,
|
||||
PublishedOnly: publishedOnly,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
func (s *Store) ListExamPrepPracticesByParent(ctx context.Context, parent domain.ExamPrepPracticeParent, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
rows, err := s.queries.ExamPrepListPracticesByParent(ctx, dbgen.ExamPrepListPracticesByParentParams{
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
ParentKind: string(parent.Kind),
|
||||
ParentID: parent.ID,
|
||||
PublishedOnly: publishedOnly,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
|
@ -107,17 +166,30 @@ func (s *Store) ListExamPrepLessonPracticesByLessonID(ctx context.Context, lesso
|
|||
if i == 0 {
|
||||
total = r.TotalCount
|
||||
}
|
||||
out = append(out, examPrepPracticeFromListRow(r))
|
||||
out = append(out, examPrepPracticeFromListRow(r, parent))
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
func (s *Store) CountExamPrepPracticesByParent(ctx context.Context, kind domain.ExamPrepParentKind, parentID int64) (int64, error) {
|
||||
return s.queries.CountExamPrepPracticesByParent(ctx, dbgen.CountExamPrepPracticesByParentParams{
|
||||
ParentKind: string(kind),
|
||||
ParentID: parentID,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) CountExamPrepPracticesByParentExcludingPractice(ctx context.Context, kind domain.ExamPrepParentKind, parentID, excludePracticeID int64) (int64, error) {
|
||||
return s.queries.CountExamPrepPracticesByParentExcludingPractice(ctx, dbgen.CountExamPrepPracticesByParentExcludingPracticeParams{
|
||||
ParentKind: string(kind),
|
||||
ParentID: parentID,
|
||||
PracticeID: excludePracticeID,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) UpdateExamPrepLessonPractice(ctx context.Context, id int64, input domain.UpdateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
var titleText pgtype.Text
|
||||
if input.Title != nil {
|
||||
titleText = pgtype.Text{String: *input.Title, Valid: true}
|
||||
} else {
|
||||
titleText = pgtype.Text{Valid: false}
|
||||
}
|
||||
qs := optionalInt8UpdateID(input.QuestionSetID)
|
||||
p, err := s.queries.ExamPrepUpdateLessonPractice(ctx, dbgen.ExamPrepUpdateLessonPracticeParams{
|
||||
|
|
@ -136,7 +208,11 @@ func (s *Store) UpdateExamPrepLessonPractice(ctx context.Context, id int64, inpu
|
|||
}
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p), nil
|
||||
parents, err := s.loadExamPrepPracticeParents(ctx, id)
|
||||
if err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return examPrepPracticeToDomain(p, parents), nil
|
||||
}
|
||||
|
||||
func (s *Store) DeleteExamPrepLessonPractice(ctx context.Context, id int64) error {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@ func (s *Store) ExamPrepCountPublishedPracticesInUnit(ctx context.Context, unitI
|
|||
return s.queries.CountPublishedExamPrepPracticesInUnit(ctx, unitID)
|
||||
}
|
||||
|
||||
// ExamPrepCountPublishedDirectPracticesInUnit returns practices attached directly to a unit.
|
||||
func (s *Store) ExamPrepCountPublishedDirectPracticesInUnit(ctx context.Context, unitID int64) (int32, error) {
|
||||
return s.queries.CountPublishedDirectExamPrepPracticesInUnit(ctx, unitID)
|
||||
}
|
||||
|
||||
// ExamPrepCountPublishedDirectPracticesInCatalogCourse returns practices attached directly to a catalog course.
|
||||
func (s *Store) ExamPrepCountPublishedDirectPracticesInCatalogCourse(ctx context.Context, catalogCourseID int64) (int32, error) {
|
||||
return s.queries.CountPublishedDirectExamPrepPracticesInCatalogCourse(ctx, catalogCourseID)
|
||||
}
|
||||
|
||||
// ExamPrepUserPracticeProgressInLesson returns published practice completion counts scoped to an exam-prep lesson.
|
||||
func (s *Store) ExamPrepUserPracticeProgressInLesson(ctx context.Context, userID, lessonID int64) (completed, total int32, err error) {
|
||||
total, err = s.queries.CountPublishedExamPrepPracticesInLesson(ctx, lessonID)
|
||||
|
|
@ -28,8 +38,40 @@ func (s *Store) ExamPrepUserPracticeProgressInLesson(ctx context.Context, userID
|
|||
return 0, 0, err
|
||||
}
|
||||
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInLesson(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInLessonParams{
|
||||
UnitModuleLessonID: lessonID,
|
||||
UserID: userID,
|
||||
ParentID: lessonID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return completed, total, nil
|
||||
}
|
||||
|
||||
// ExamPrepUserDirectPracticeProgressInUnit returns completion counts for practices attached directly to a unit.
|
||||
func (s *Store) ExamPrepUserDirectPracticeProgressInUnit(ctx context.Context, userID, unitID int64) (completed, total int32, err error) {
|
||||
total, err = s.queries.CountPublishedDirectExamPrepPracticesInUnit(ctx, unitID)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
completed, err = s.queries.CountUserCompletedPublishedDirectExamPrepPracticesInUnit(ctx, dbgen.CountUserCompletedPublishedDirectExamPrepPracticesInUnitParams{
|
||||
ParentID: unitID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return completed, total, nil
|
||||
}
|
||||
|
||||
// ExamPrepUserDirectPracticeProgressInCatalogCourse returns completion counts for practices attached directly to a catalog course.
|
||||
func (s *Store) ExamPrepUserDirectPracticeProgressInCatalogCourse(ctx context.Context, userID, catalogCourseID int64) (completed, total int32, err error) {
|
||||
total, err = s.queries.CountPublishedDirectExamPrepPracticesInCatalogCourse(ctx, catalogCourseID)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
completed, err = s.queries.CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse(ctx, dbgen.CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourseParams{
|
||||
ParentID: catalogCourseID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
|
|
@ -60,8 +102,8 @@ func (s *Store) ExamPrepUserPracticeProgressInUnit(ctx context.Context, userID,
|
|||
return 0, 0, err
|
||||
}
|
||||
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInUnit(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInUnitParams{
|
||||
UnitID: unitID,
|
||||
UserID: userID,
|
||||
ParentID: unitID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
|
|
@ -76,8 +118,8 @@ func (s *Store) ExamPrepUserPracticeProgressInCatalogCourse(ctx context.Context,
|
|||
return 0, 0, err
|
||||
}
|
||||
completed, err = s.queries.CountUserCompletedPublishedExamPrepPracticesInCatalogCourse(ctx, dbgen.CountUserCompletedPublishedExamPrepPracticesInCatalogCourseParams{
|
||||
CatalogCourseID: catalogCourseID,
|
||||
UserID: userID,
|
||||
ParentID: catalogCourseID,
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ var ErrUnitNotFound = errors.New("exam prep unit not found")
|
|||
var ErrModuleNotFound = errors.New("exam prep module not found")
|
||||
var ErrLessonNotFound = errors.New("exam prep lesson not found")
|
||||
var ErrPracticeNotFound = errors.New("exam prep practice not found")
|
||||
var ErrExamPrepPracticeParentLimitExceeded = errors.New("this catalog course, unit, or lesson already has a practice")
|
||||
|
||||
// examPrepStore is implemented by *repository.Store (catalog courses, units, modules, lessons, practices, personas).
|
||||
type examPrepStore interface {
|
||||
|
|
@ -363,8 +364,19 @@ func (s *Service) ensureLesson(ctx context.Context, lessonID int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateExamPrepPractice(ctx context.Context, lessonID int64, input domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
if err := s.ensureLesson(ctx, lessonID); err != nil {
|
||||
func (s *Service) ensureExamPrepPracticeParentAvailable(ctx context.Context, parent domain.ExamPrepPracticeParent) error {
|
||||
count, err := s.store.CountExamPrepPracticesByParent(ctx, parent.Kind, parent.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return ErrExamPrepPracticeParentLimitExceeded
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) createExamPrepPractice(ctx context.Context, parent domain.ExamPrepPracticeParent, input domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
if err := s.ensureExamPrepPracticeParentAvailable(ctx, parent); err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
if input.PersonaID != nil {
|
||||
|
|
@ -372,13 +384,10 @@ func (s *Service) CreateExamPrepPractice(ctx context.Context, lessonID int64, in
|
|||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
}
|
||||
return s.store.CreateExamPrepLessonPractice(ctx, lessonID, input)
|
||||
return s.store.CreateExamPrepPractice(ctx, parent, input)
|
||||
}
|
||||
|
||||
func (s *Service) ListExamPrepPracticesByLesson(ctx context.Context, lessonID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
if err := s.ensureLesson(ctx, lessonID); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
func (s *Service) listExamPrepPractices(ctx context.Context, parent domain.ExamPrepPracticeParent, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
|
|
@ -388,7 +397,67 @@ func (s *Service) ListExamPrepPracticesByLesson(ctx context.Context, lessonID in
|
|||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
return s.store.ListExamPrepLessonPracticesByLessonID(ctx, lessonID, publishedOnly, limit, offset)
|
||||
return s.store.ListExamPrepPracticesByParent(ctx, parent, publishedOnly, limit, offset)
|
||||
}
|
||||
|
||||
func (s *Service) CreateExamPrepPractice(ctx context.Context, lessonID int64, input domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
if err := s.ensureLesson(ctx, lessonID); err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return s.createExamPrepPractice(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindLesson,
|
||||
ID: lessonID,
|
||||
}, input)
|
||||
}
|
||||
|
||||
func (s *Service) CreateExamPrepPracticeForCatalogCourse(ctx context.Context, catalogCourseID int64, input domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
if err := s.ensureCatalogCourse(ctx, catalogCourseID); err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return s.createExamPrepPractice(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindCatalogCourse,
|
||||
ID: catalogCourseID,
|
||||
}, input)
|
||||
}
|
||||
|
||||
func (s *Service) CreateExamPrepPracticeForUnit(ctx context.Context, unitID int64, input domain.CreateExamPrepPracticeInput) (domain.ExamPrepPractice, error) {
|
||||
if err := s.ensureUnit(ctx, unitID); err != nil {
|
||||
return domain.ExamPrepPractice{}, err
|
||||
}
|
||||
return s.createExamPrepPractice(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindUnit,
|
||||
ID: unitID,
|
||||
}, input)
|
||||
}
|
||||
|
||||
func (s *Service) ListExamPrepPracticesByLesson(ctx context.Context, lessonID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
if err := s.ensureLesson(ctx, lessonID); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return s.listExamPrepPractices(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindLesson,
|
||||
ID: lessonID,
|
||||
}, publishedOnly, limit, offset)
|
||||
}
|
||||
|
||||
func (s *Service) ListExamPrepPracticesByCatalogCourse(ctx context.Context, catalogCourseID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
if err := s.ensureCatalogCourse(ctx, catalogCourseID); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return s.listExamPrepPractices(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindCatalogCourse,
|
||||
ID: catalogCourseID,
|
||||
}, publishedOnly, limit, offset)
|
||||
}
|
||||
|
||||
func (s *Service) ListExamPrepPracticesByUnit(ctx context.Context, unitID int64, publishedOnly bool, limit, offset int32) ([]domain.ExamPrepPractice, int64, error) {
|
||||
if err := s.ensureUnit(ctx, unitID); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return s.listExamPrepPractices(ctx, domain.ExamPrepPracticeParent{
|
||||
Kind: domain.ExamPrepParentKindUnit,
|
||||
ID: unitID,
|
||||
}, publishedOnly, limit, offset)
|
||||
}
|
||||
|
||||
func (s *Service) GetExamPrepPracticeByID(ctx context.Context, id int64) (domain.ExamPrepPractice, error) {
|
||||
|
|
|
|||
|
|
@ -25,27 +25,31 @@ type epLessonAccum struct {
|
|||
}
|
||||
|
||||
type epModuleAccum struct {
|
||||
id int64
|
||||
name string
|
||||
id int64
|
||||
name string
|
||||
sortOrder int32
|
||||
lessons map[int64]*epLessonAccum
|
||||
order []int64
|
||||
lessons map[int64]*epLessonAccum
|
||||
order []int64
|
||||
}
|
||||
|
||||
type epUnitAccum struct {
|
||||
id int64
|
||||
name string
|
||||
id int64
|
||||
name string
|
||||
sortOrder int32
|
||||
modules map[int64]*epModuleAccum
|
||||
order []int64
|
||||
practices []domain.AdminExamPrepPracticeLearningEntry
|
||||
seen map[int64]struct{}
|
||||
modules map[int64]*epModuleAccum
|
||||
order []int64
|
||||
}
|
||||
|
||||
type epCatalogAccum struct {
|
||||
id int64
|
||||
name string
|
||||
id int64
|
||||
name string
|
||||
sortOrder int32
|
||||
units map[int64]*epUnitAccum
|
||||
order []int64
|
||||
practices []domain.AdminExamPrepPracticeLearningEntry
|
||||
seen map[int64]struct{}
|
||||
units map[int64]*epUnitAccum
|
||||
order []int64
|
||||
}
|
||||
|
||||
type examPrepActivityTreeBuilder struct {
|
||||
|
|
@ -63,66 +67,149 @@ func (b *examPrepActivityTreeBuilder) ensureCatalog(row dbgen.ListUserExamPrepFl
|
|||
}
|
||||
c := &epCatalogAccum{
|
||||
id: row.CatalogCourseID, name: row.CatalogCourseName, sortOrder: row.CatalogCourseSortOrder,
|
||||
units: make(map[int64]*epUnitAccum),
|
||||
seen: make(map[int64]struct{}), units: make(map[int64]*epUnitAccum),
|
||||
}
|
||||
b.catalogs[row.CatalogCourseID] = c
|
||||
b.order = append(b.order, row.CatalogCourseID)
|
||||
return c
|
||||
}
|
||||
|
||||
func appendExamPrepPractice(seen map[int64]struct{}, practices *[]domain.AdminExamPrepPracticeLearningEntry, row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) {
|
||||
if seen == nil {
|
||||
return
|
||||
}
|
||||
if _, ok := seen[row.ExamPrepPracticeID]; ok {
|
||||
return
|
||||
}
|
||||
seen[row.ExamPrepPracticeID] = struct{}{}
|
||||
*practices = append(*practices, domain.AdminExamPrepPracticeLearningEntry{
|
||||
ExamPrepPracticeID: row.ExamPrepPracticeID,
|
||||
Title: row.PracticeTitle,
|
||||
CompletedAt: row.ActivityAt.Time,
|
||||
})
|
||||
}
|
||||
|
||||
func examPrepActivityUnitID(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) (int64, bool) {
|
||||
return pgInterfaceInt64(row.UnitID)
|
||||
}
|
||||
|
||||
func examPrepActivityUnitName(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) string {
|
||||
return pgInterfaceString(row.UnitName)
|
||||
}
|
||||
|
||||
func examPrepActivityUnitSortOrder(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) int32 {
|
||||
v, ok := pgInterfaceInt64(row.UnitSortOrder)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
return int32(v)
|
||||
}
|
||||
|
||||
func pgInterfaceInt64(v interface{}) (int64, bool) {
|
||||
if v == nil {
|
||||
return 0, false
|
||||
}
|
||||
switch n := v.(type) {
|
||||
case int64:
|
||||
return n, true
|
||||
case int32:
|
||||
return int64(n), true
|
||||
case int:
|
||||
return int64(n), true
|
||||
case float64:
|
||||
return int64(n), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func pgInterfaceString(v interface{}) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (ca *epCatalogAccum) ensureUnit(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) *epUnitAccum {
|
||||
if u, ok := ca.units[row.UnitID]; ok {
|
||||
unitID, ok := examPrepActivityUnitID(row)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if u, exists := ca.units[unitID]; exists {
|
||||
return u
|
||||
}
|
||||
u := &epUnitAccum{
|
||||
id: row.UnitID, name: row.UnitName, sortOrder: row.UnitSortOrder,
|
||||
modules: make(map[int64]*epModuleAccum),
|
||||
id: unitID, name: examPrepActivityUnitName(row), sortOrder: examPrepActivityUnitSortOrder(row),
|
||||
seen: make(map[int64]struct{}), modules: make(map[int64]*epModuleAccum),
|
||||
}
|
||||
ca.units[row.UnitID] = u
|
||||
ca.order = append(ca.order, row.UnitID)
|
||||
ca.units[unitID] = u
|
||||
ca.order = append(ca.order, unitID)
|
||||
return u
|
||||
}
|
||||
|
||||
func (ua *epUnitAccum) ensureModule(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) *epModuleAccum {
|
||||
if m, ok := ua.modules[row.ModuleID]; ok {
|
||||
if !row.ModuleID.Valid {
|
||||
return nil
|
||||
}
|
||||
moduleID := row.ModuleID.Int64
|
||||
if m, ok := ua.modules[moduleID]; ok {
|
||||
return m
|
||||
}
|
||||
m := &epModuleAccum{
|
||||
id: row.ModuleID, name: row.ModuleName, sortOrder: row.ModuleSortOrder,
|
||||
id: moduleID, name: row.ModuleName.String, sortOrder: row.ModuleSortOrder.Int32,
|
||||
lessons: make(map[int64]*epLessonAccum),
|
||||
}
|
||||
ua.modules[row.ModuleID] = m
|
||||
ua.order = append(ua.order, row.ModuleID)
|
||||
ua.modules[moduleID] = m
|
||||
ua.order = append(ua.order, moduleID)
|
||||
return m
|
||||
}
|
||||
|
||||
func (ma *epModuleAccum) ensureLesson(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) *epLessonAccum {
|
||||
if l, ok := ma.lessons[row.LessonID]; ok {
|
||||
if !row.LessonID.Valid {
|
||||
return nil
|
||||
}
|
||||
lessonID := row.LessonID.Int64
|
||||
if l, ok := ma.lessons[lessonID]; ok {
|
||||
return l
|
||||
}
|
||||
l := &epLessonAccum{
|
||||
id: row.LessonID, title: row.LessonTitle, sortOrder: row.LessonSortOrder,
|
||||
id: lessonID, title: row.LessonTitle.String, sortOrder: row.LessonSortOrder.Int32,
|
||||
seen: make(map[int64]struct{}),
|
||||
}
|
||||
ma.lessons[row.LessonID] = l
|
||||
ma.order = append(ma.order, row.LessonID)
|
||||
ma.lessons[lessonID] = l
|
||||
ma.order = append(ma.order, lessonID)
|
||||
return l
|
||||
}
|
||||
|
||||
func (b *examPrepActivityTreeBuilder) ingest(row dbgen.ListUserExamPrepFlatLearningActivityByUserRow) {
|
||||
c := b.ensureCatalog(row)
|
||||
u := c.ensureUnit(row)
|
||||
m := u.ensureModule(row)
|
||||
l := m.ensureLesson(row)
|
||||
if _, ok := l.seen[row.ExamPrepPracticeID]; ok {
|
||||
if _, hasUnit := examPrepActivityUnitID(row); !hasUnit {
|
||||
appendExamPrepPractice(c.seen, &c.practices, row)
|
||||
return
|
||||
}
|
||||
l.seen[row.ExamPrepPracticeID] = struct{}{}
|
||||
l.practices = append(l.practices, domain.AdminExamPrepPracticeLearningEntry{
|
||||
ExamPrepPracticeID: row.ExamPrepPracticeID,
|
||||
Title: row.PracticeTitle,
|
||||
CompletedAt: row.ActivityAt.Time,
|
||||
})
|
||||
u := c.ensureUnit(row)
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
if !row.ModuleID.Valid {
|
||||
appendExamPrepPractice(u.seen, &u.practices, row)
|
||||
return
|
||||
}
|
||||
m := u.ensureModule(row)
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
if !row.LessonID.Valid {
|
||||
return
|
||||
}
|
||||
l := m.ensureLesson(row)
|
||||
if l == nil {
|
||||
return
|
||||
}
|
||||
appendExamPrepPractice(l.seen, &l.practices, row)
|
||||
}
|
||||
|
||||
func buildAdminExamPrepLearningActivityTree(userID int64, rows []dbgen.ListUserExamPrepFlatLearningActivityByUserRow) domain.AdminExamPrepUserLearningActivityTree {
|
||||
|
|
@ -152,11 +239,11 @@ func buildAdminExamPrepLearningActivityTree(userID int64, rows []dbgen.ListUserE
|
|||
})
|
||||
}
|
||||
units = append(units, domain.AdminExamPrepUnitLearningEntry{
|
||||
ID: ua.id, Name: ua.name, SortOrder: ua.sortOrder, Modules: modules,
|
||||
ID: ua.id, Name: ua.name, SortOrder: ua.sortOrder, Practices: ua.practices, Modules: modules,
|
||||
})
|
||||
}
|
||||
catalogs = append(catalogs, domain.AdminExamPrepCatalogCourseLearningEntry{
|
||||
ID: ca.id, Name: ca.name, SortOrder: ca.sortOrder, Units: units,
|
||||
ID: ca.id, Name: ca.name, SortOrder: ca.sortOrder, Practices: ca.practices, Units: units,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const (
|
|||
errPrevExamPrepUnit = "Complete the previous unit in this catalog course first."
|
||||
errPrevExamPrepModule = "Complete the previous module in this unit first."
|
||||
errPrevExamPrepLesson = "Complete the previous lesson in this module first."
|
||||
errPrevExamPrepPractice = "Complete the previous practice in this lesson first."
|
||||
errPrevExamPrepPractice = "Complete the previous practice first."
|
||||
)
|
||||
|
||||
// Service enforces sequential LMS access for learners and records lesson progress.
|
||||
|
|
@ -257,7 +257,7 @@ func (s *Service) CanAccessExamPrepLesson(ctx context.Context, userID, lessonID
|
|||
return true, "", nil
|
||||
}
|
||||
|
||||
// CanAccessExamPrepPracticeByQuestionSet enforces lesson chain and within-lesson practice order for exam-prep practices.
|
||||
// CanAccessExamPrepPracticeByQuestionSet enforces parent chain and within-parent practice order for exam-prep practices.
|
||||
// Returns ok=true with no error when the question set is not linked to exam_prep.lesson_practices.
|
||||
func (s *Service) CanAccessExamPrepPracticeByQuestionSet(ctx context.Context, userID, questionSetID int64) (ok bool, reason string, err error) {
|
||||
practice, found, err := s.store.TryGetExamPrepLessonPracticeByQuestionSetID(ctx, questionSetID)
|
||||
|
|
@ -270,7 +270,20 @@ func (s *Service) CanAccessExamPrepPracticeByQuestionSet(ctx context.Context, us
|
|||
if !practice.VisibleToLearners() {
|
||||
return false, "Practice not found", nil
|
||||
}
|
||||
ok, reason, err = s.CanAccessExamPrepLesson(ctx, userID, practice.LessonID)
|
||||
parent, hasParent := domain.ExamPrepPracticePrimaryParent(practice)
|
||||
if !hasParent {
|
||||
return true, "", nil
|
||||
}
|
||||
switch parent.Kind {
|
||||
case domain.ExamPrepParentKindCatalogCourse:
|
||||
ok, reason, err = s.CanAccessExamPrepCatalogCourse(ctx, userID, parent.ID)
|
||||
case domain.ExamPrepParentKindUnit:
|
||||
ok, reason, err = s.CanAccessExamPrepUnit(ctx, userID, parent.ID)
|
||||
case domain.ExamPrepParentKindLesson:
|
||||
ok, reason, err = s.CanAccessExamPrepLesson(ctx, userID, parent.ID)
|
||||
default:
|
||||
return true, "", nil
|
||||
}
|
||||
if err != nil || !ok {
|
||||
return ok, reason, err
|
||||
}
|
||||
|
|
@ -661,7 +674,31 @@ func (s *Service) examPrepModuleProgress(ctx context.Context, userID, moduleID i
|
|||
return fraction, done, completed, total, nil
|
||||
}
|
||||
|
||||
func (s *Service) hasCompletedDirectUnitPractice(ctx context.Context, userID, unitID int64) (bool, error) {
|
||||
completed, total, err := s.store.ExamPrepUserDirectPracticeProgressInUnit(ctx, userID, unitID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return total > 0 && completed > 0, nil
|
||||
}
|
||||
|
||||
func (s *Service) hasCompletedDirectCatalogCoursePractice(ctx context.Context, userID, catalogCourseID int64) (bool, error) {
|
||||
completed, total, err := s.store.ExamPrepUserDirectPracticeProgressInCatalogCourse(ctx, userID, catalogCourseID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return total > 0 && completed > 0, nil
|
||||
}
|
||||
|
||||
func (s *Service) examPrepUnitProgress(ctx context.Context, userID, unitID int64) (fraction float64, done bool, completed, total int32, err error) {
|
||||
directDone, directErr := s.hasCompletedDirectUnitPractice(ctx, userID, unitID)
|
||||
if directErr != nil {
|
||||
return 0, false, 0, 0, directErr
|
||||
}
|
||||
if directDone {
|
||||
return 1, true, 1, 1, nil
|
||||
}
|
||||
|
||||
moduleIDs, err := s.store.ListPublishedExamPrepUnitModuleIDsByUnit(ctx, unitID)
|
||||
if err != nil {
|
||||
return 0, false, 0, 0, err
|
||||
|
|
@ -690,6 +727,14 @@ func (s *Service) examPrepUnitProgress(ctx context.Context, userID, unitID int64
|
|||
}
|
||||
|
||||
func (s *Service) examPrepCatalogCourseProgress(ctx context.Context, userID, catalogCourseID int64) (fraction float64, done bool, completed, total int32, err error) {
|
||||
directDone, directErr := s.hasCompletedDirectCatalogCoursePractice(ctx, userID, catalogCourseID)
|
||||
if directErr != nil {
|
||||
return 0, false, 0, 0, directErr
|
||||
}
|
||||
if directDone {
|
||||
return 1, true, 1, 1, nil
|
||||
}
|
||||
|
||||
unitIDs, err := s.store.ListPublishedExamPrepUnitIDsByCatalogCourse(ctx, catalogCourseID)
|
||||
if err != nil {
|
||||
return 0, false, 0, 0, err
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ var AllPermissions = []domain.PermissionSeed{
|
|||
{Key: "exam_prep.lessons.update", Name: "Update Exam Prep Lesson", Description: "Update an exam prep lesson", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.lessons.delete", Name: "Delete Exam Prep Lesson", Description: "Delete an exam prep lesson", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.lessons.reorder", Name: "Reorder Exam Prep Lessons", Description: "Reorder lessons within an exam prep unit module", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.create", Name: "Create Exam Prep Practice", Description: "Create a practice under an exam prep lesson (references question_sets)", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.create", Name: "Create Exam Prep Practice", Description: "Create a practice under an exam prep catalog course, unit, or lesson (references question_sets)", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.list_by_catalog_course", Name: "List Exam Prep Practices by Catalog Course", Description: "List practices for an exam prep catalog course", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.list_by_unit", Name: "List Exam Prep Practices by Unit", Description: "List practices for an exam prep unit", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.list_by_lesson", Name: "List Exam Prep Practices by Lesson", Description: "List practices for an exam prep lesson", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.get", Name: "Get Exam Prep Practice", Description: "Get an exam prep practice by ID", GroupName: "Exam Prep"},
|
||||
{Key: "exam_prep.practices.update", Name: "Update Exam Prep Practice", Description: "Update an exam prep practice", GroupName: "Exam Prep"},
|
||||
|
|
@ -359,7 +361,7 @@ var defaultStudentLearnerPermissions = []string{
|
|||
"exam_prep.units.list", "exam_prep.units.get",
|
||||
"exam_prep.modules.list", "exam_prep.modules.get",
|
||||
"exam_prep.lessons.list_by_module", "exam_prep.lessons.get",
|
||||
"exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
"exam_prep.practices.list_by_catalog_course", "exam_prep.practices.list_by_unit", "exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
"lms.get_my_progress",
|
||||
|
||||
// Questions (read + attempt)
|
||||
|
|
@ -423,7 +425,7 @@ var DefaultRolePermissions = map[string][]string{
|
|||
"exam_prep.units.create", "exam_prep.units.list", "exam_prep.units.get", "exam_prep.units.update", "exam_prep.units.delete", "exam_prep.units.reorder",
|
||||
"exam_prep.modules.create", "exam_prep.modules.list", "exam_prep.modules.get", "exam_prep.modules.update", "exam_prep.modules.delete", "exam_prep.modules.reorder",
|
||||
"exam_prep.lessons.create", "exam_prep.lessons.list_by_module", "exam_prep.lessons.get", "exam_prep.lessons.update", "exam_prep.lessons.delete", "exam_prep.lessons.reorder",
|
||||
"exam_prep.practices.create", "exam_prep.practices.list_by_lesson", "exam_prep.practices.get", "exam_prep.practices.update", "exam_prep.practices.delete",
|
||||
"exam_prep.practices.create", "exam_prep.practices.list_by_catalog_course", "exam_prep.practices.list_by_unit", "exam_prep.practices.list_by_lesson", "exam_prep.practices.get", "exam_prep.practices.update", "exam_prep.practices.delete",
|
||||
"lms.get_my_progress",
|
||||
|
||||
// Modules
|
||||
|
|
@ -542,7 +544,7 @@ var DefaultRolePermissions = map[string][]string{
|
|||
"exam_prep.units.list", "exam_prep.units.get",
|
||||
"exam_prep.modules.list", "exam_prep.modules.get",
|
||||
"exam_prep.lessons.list_by_module", "exam_prep.lessons.get",
|
||||
"exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
"exam_prep.practices.list_by_catalog_course", "exam_prep.practices.list_by_unit", "exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
"lms.get_my_progress",
|
||||
|
||||
"personas.create", "personas.list", "personas.get", "personas.update", "personas.delete",
|
||||
|
|
@ -609,7 +611,7 @@ var DefaultRolePermissions = map[string][]string{
|
|||
"exam_prep.units.list", "exam_prep.units.get",
|
||||
"exam_prep.modules.list", "exam_prep.modules.get",
|
||||
"exam_prep.lessons.list_by_module", "exam_prep.lessons.get",
|
||||
"exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
"exam_prep.practices.list_by_catalog_course", "exam_prep.practices.list_by_unit", "exam_prep.practices.list_by_lesson", "exam_prep.practices.get",
|
||||
|
||||
"personas.list", "personas.get",
|
||||
|
||||
|
|
|
|||
|
|
@ -319,7 +319,20 @@ func (a *App) examPrepEffectiveTierForPractice(ctx context.Context, practiceID i
|
|||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
return a.examPrepEffectiveTierForLesson(ctx, practice.LessonID)
|
||||
parent, ok := domain.ExamPrepPracticePrimaryParent(practice)
|
||||
if !ok {
|
||||
return "", false, nil
|
||||
}
|
||||
switch parent.Kind {
|
||||
case domain.ExamPrepParentKindCatalogCourse:
|
||||
return a.examPrepEffectiveTierForCatalogCourse(ctx, parent.ID)
|
||||
case domain.ExamPrepParentKindUnit:
|
||||
return a.examPrepEffectiveTierForUnit(ctx, parent.ID)
|
||||
case domain.ExamPrepParentKindLesson:
|
||||
return a.examPrepEffectiveTierForLesson(ctx, parent.ID)
|
||||
default:
|
||||
return "", false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) lmsEffectiveTierForPractice(ctx context.Context, practiceID int64) (domain.ContentAccessTier, bool, error) {
|
||||
|
|
|
|||
|
|
@ -39,17 +39,8 @@ func (h *Handler) CreateExamPrepPractice(c *fiber.Ctx) error {
|
|||
}
|
||||
p, err := h.examPrepSvc.CreateExamPrepPractice(c.Context(), lessonID, req)
|
||||
if err != nil {
|
||||
if errors.Is(err, examprep.ErrLessonNotFound) {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Lesson not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
if errors.Is(err, domain.ErrPersonaNotFound) {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Persona not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
if resp := h.mapCreateExamPrepPracticeError(c, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
||||
Message: "Failed to create practice",
|
||||
|
|
@ -85,28 +76,15 @@ func (h *Handler) ListExamPrepPracticesByLesson(c *fiber.Ctx) error {
|
|||
publishedOnly := !h.canManageExamPrepPractices(c)
|
||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByLesson(c.Context(), lessonID, publishedOnly, int32(limit), int32(offset))
|
||||
if err != nil {
|
||||
if errors.Is(err, examprep.ErrLessonNotFound) {
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Lesson not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, limit, offset, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
||||
Message: "Failed to list practices",
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Practices retrieved successfully",
|
||||
Data: fiber.Map{
|
||||
"practices": items,
|
||||
"total_count": total,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
},
|
||||
Success: true,
|
||||
StatusCode: fiber.StatusOK,
|
||||
})
|
||||
return h.listExamPrepPracticesResponse(c, items, total, limit, offset, nil)
|
||||
}
|
||||
|
||||
// GetExamPrepPracticeByID godoc
|
||||
|
|
@ -230,3 +208,157 @@ func (h *Handler) DeleteExamPrepPractice(c *fiber.Ctx) error {
|
|||
StatusCode: fiber.StatusOK,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) mapCreateExamPrepPracticeError(c *fiber.Ctx, err error) error {
|
||||
switch {
|
||||
case errors.Is(err, examprep.ErrLessonNotFound), errors.Is(err, examprep.ErrUnitNotFound), errors.Is(err, examprep.ErrCatalogCourseNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Parent not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
case errors.Is(err, domain.ErrPersonaNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
Message: "Persona not found",
|
||||
Error: err.Error(),
|
||||
})
|
||||
case errors.Is(err, examprep.ErrExamPrepPracticeParentLimitExceeded):
|
||||
return c.Status(fiber.StatusConflict).JSON(domain.ErrorResponse{
|
||||
Message: "This parent already has a practice",
|
||||
Error: err.Error(),
|
||||
})
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) listExamPrepPracticesResponse(c *fiber.Ctx, items []domain.ExamPrepPractice, total int64, limit, offset int, notFound error) error {
|
||||
if notFound != nil {
|
||||
switch {
|
||||
case errors.Is(notFound, examprep.ErrLessonNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Lesson not found", Error: notFound.Error()})
|
||||
case errors.Is(notFound, examprep.ErrUnitNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Unit not found", Error: notFound.Error()})
|
||||
case errors.Is(notFound, examprep.ErrCatalogCourseNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{Message: "Catalog course not found", Error: notFound.Error()})
|
||||
}
|
||||
}
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Practices retrieved successfully",
|
||||
Data: fiber.Map{
|
||||
"practices": items,
|
||||
"total_count": total,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
},
|
||||
Success: true,
|
||||
StatusCode: fiber.StatusOK,
|
||||
})
|
||||
}
|
||||
|
||||
// CreateExamPrepPracticeForCatalogCourse godoc
|
||||
// @Summary Create exam-prep practice under a catalog course
|
||||
// @Tags exam-prep
|
||||
// @Param catalogCourseId path int true "Exam prep catalog course ID"
|
||||
// @Param body body domain.CreateExamPrepPracticeInput true "Practice"
|
||||
// @Router /api/v1/exam-prep/catalog-courses/{catalogCourseId}/practices [post]
|
||||
func (h *Handler) CreateExamPrepPracticeForCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid catalog course id", Error: err.Error()})
|
||||
}
|
||||
var req domain.CreateExamPrepPracticeInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid request body", Error: err.Error()})
|
||||
}
|
||||
if valErrs, ok := h.validator.Validate(c, req); !ok {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Validation failed", Error: firstValidationError(valErrs)})
|
||||
}
|
||||
p, err := h.examPrepSvc.CreateExamPrepPracticeForCatalogCourse(c.Context(), catalogCourseID, req)
|
||||
if err != nil {
|
||||
if resp := h.mapCreateExamPrepPracticeError(c, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to create practice", Error: err.Error()})
|
||||
}
|
||||
h.recordActivity(c, domain.ActionExamPrepPracticeCreated, domain.ResourceExamPrepPractice, &p.ID, "Created exam prep practice: "+p.Title, nil)
|
||||
return c.Status(fiber.StatusCreated).JSON(domain.Response{
|
||||
Message: "Practice created successfully", Data: p, Success: true, StatusCode: fiber.StatusCreated,
|
||||
})
|
||||
}
|
||||
|
||||
// ListExamPrepPracticesByCatalogCourse godoc
|
||||
// @Summary List exam-prep practices for a catalog course
|
||||
// @Tags exam-prep
|
||||
// @Param catalogCourseId path int true "Exam prep catalog course ID"
|
||||
// @Router /api/v1/exam-prep/catalog-courses/{catalogCourseId}/practices [get]
|
||||
func (h *Handler) ListExamPrepPracticesByCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid catalog course id", Error: err.Error()})
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByCatalogCourse(c.Context(), catalogCourseID, publishedOnly, int32(limit), int32(offset))
|
||||
if err != nil {
|
||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, limit, offset, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to list practices", Error: err.Error()})
|
||||
}
|
||||
return h.listExamPrepPracticesResponse(c, items, total, limit, offset, nil)
|
||||
}
|
||||
|
||||
// CreateExamPrepPracticeForUnit godoc
|
||||
// @Summary Create exam-prep practice under a unit
|
||||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Exam prep unit ID"
|
||||
// @Param body body domain.CreateExamPrepPracticeInput true "Practice"
|
||||
// @Router /api/v1/exam-prep/units/{unitId}/practices [post]
|
||||
func (h *Handler) CreateExamPrepPracticeForUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid unit id", Error: err.Error()})
|
||||
}
|
||||
var req domain.CreateExamPrepPracticeInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid request body", Error: err.Error()})
|
||||
}
|
||||
if valErrs, ok := h.validator.Validate(c, req); !ok {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Validation failed", Error: firstValidationError(valErrs)})
|
||||
}
|
||||
p, err := h.examPrepSvc.CreateExamPrepPracticeForUnit(c.Context(), unitID, req)
|
||||
if err != nil {
|
||||
if resp := h.mapCreateExamPrepPracticeError(c, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to create practice", Error: err.Error()})
|
||||
}
|
||||
h.recordActivity(c, domain.ActionExamPrepPracticeCreated, domain.ResourceExamPrepPractice, &p.ID, "Created exam prep practice: "+p.Title, nil)
|
||||
return c.Status(fiber.StatusCreated).JSON(domain.Response{
|
||||
Message: "Practice created successfully", Data: p, Success: true, StatusCode: fiber.StatusCreated,
|
||||
})
|
||||
}
|
||||
|
||||
// ListExamPrepPracticesByUnit godoc
|
||||
// @Summary List exam-prep practices for a unit
|
||||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Exam prep unit ID"
|
||||
// @Router /api/v1/exam-prep/units/{unitId}/practices [get]
|
||||
func (h *Handler) ListExamPrepPracticesByUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{Message: "Invalid unit id", Error: err.Error()})
|
||||
}
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
publishedOnly := !h.canManageExamPrepPractices(c)
|
||||
items, total, err := h.examPrepSvc.ListExamPrepPracticesByUnit(c.Context(), unitID, publishedOnly, int32(limit), int32(offset))
|
||||
if err != nil {
|
||||
if resp := h.listExamPrepPracticesResponse(c, nil, 0, limit, offset, err); resp != nil {
|
||||
return resp
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{Message: "Failed to list practices", Error: err.Error()})
|
||||
}
|
||||
return h.listExamPrepPracticesResponse(c, items, total, limit, offset, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -464,7 +464,20 @@ func (a *App) examPrepCategoryByPracticeID(ctx context.Context, practiceID int64
|
|||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
return a.examPrepCategoryByLessonID(ctx, practice.LessonID)
|
||||
parent, ok := domain.ExamPrepPracticePrimaryParent(practice)
|
||||
if !ok {
|
||||
return "", false, nil
|
||||
}
|
||||
switch parent.Kind {
|
||||
case domain.ExamPrepParentKindCatalogCourse:
|
||||
return a.examPrepCategoryByCatalogCourseID(ctx, parent.ID)
|
||||
case domain.ExamPrepParentKindUnit:
|
||||
return a.examPrepCategoryByUnitID(ctx, parent.ID)
|
||||
case domain.ExamPrepParentKindLesson:
|
||||
return a.examPrepCategoryByLessonID(ctx, parent.ID)
|
||||
default:
|
||||
return "", false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) RequirePermission(permKey string) fiber.Handler {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ func (a *App) initAppRoutes() {
|
|||
examPrep.Get("/catalog-courses/:id", a.RequirePermission("exam_prep.catalog_courses.get"), h.GetExamPrepCatalogCourseByID)
|
||||
examPrep.Put("/catalog-courses/:id", a.RequirePermission("exam_prep.catalog_courses.update"), h.UpdateExamPrepCatalogCourse)
|
||||
examPrep.Delete("/catalog-courses/:id", a.RequirePermission("exam_prep.catalog_courses.delete"), h.DeleteExamPrepCatalogCourse)
|
||||
examPrep.Post("/catalog-courses/:catalogCourseId/practices", a.RequirePermission("exam_prep.practices.create"), h.CreateExamPrepPracticeForCatalogCourse)
|
||||
examPrep.Get("/catalog-courses/:catalogCourseId/practices", a.RequirePermission("exam_prep.practices.list_by_catalog_course"), h.ListExamPrepPracticesByCatalogCourse)
|
||||
|
||||
examPrep.Post("/catalog-courses/:catalogCourseId/units", a.RequirePermission("exam_prep.units.create"), h.CreateExamPrepUnit)
|
||||
examPrep.Get("/catalog-courses/:catalogCourseId/units", a.RequirePermission("exam_prep.units.list"), h.ListExamPrepUnitsByCatalogCourse)
|
||||
|
|
@ -130,6 +132,8 @@ func (a *App) initAppRoutes() {
|
|||
examPrep.Get("/units/:id", a.RequirePermission("exam_prep.units.get"), h.GetExamPrepUnitByID)
|
||||
examPrep.Put("/units/:id", a.RequirePermission("exam_prep.units.update"), h.UpdateExamPrepUnit)
|
||||
examPrep.Delete("/units/:id", a.RequirePermission("exam_prep.units.delete"), h.DeleteExamPrepUnit)
|
||||
examPrep.Post("/units/:unitId/practices", a.RequirePermission("exam_prep.practices.create"), h.CreateExamPrepPracticeForUnit)
|
||||
examPrep.Get("/units/:unitId/practices", a.RequirePermission("exam_prep.practices.list_by_unit"), h.ListExamPrepPracticesByUnit)
|
||||
|
||||
// Courses
|
||||
groupV1.Post("/programs/:id/courses", a.authMiddleware, a.RequirePermission("courses.create"), h.CreateCourse)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user