Expose has_practice booleans for LMS and pre-exam hierarchy entities, wire SQL/repository mappings, and regenerate SQLC/Swagger artifacts. Also update the Resend sender display name for outbound emails. Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
2.3 KiB
SQL
90 lines
2.3 KiB
SQL
-- name: ExamPrepCreateUnitModule :one
|
|
INSERT INTO exam_prep.unit_modules (unit_id, name, description, thumbnail, icon, sort_order)
|
|
SELECT
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
coalesce((
|
|
SELECT
|
|
max(m.sort_order)
|
|
FROM exam_prep.unit_modules m
|
|
WHERE
|
|
m.unit_id = $1), 0) + 1
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: ExamPrepGetUnitModuleByID :one
|
|
SELECT
|
|
m.*,
|
|
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
|
|
WHERE l.unit_module_id = m.id
|
|
) AS has_practice
|
|
FROM exam_prep.unit_modules m
|
|
WHERE m.id = $1;
|
|
|
|
-- name: ExamPrepListUnitModuleIDsByUnit :many
|
|
SELECT
|
|
m.id
|
|
FROM exam_prep.unit_modules m
|
|
WHERE
|
|
m.unit_id = $1
|
|
ORDER BY
|
|
m.id;
|
|
|
|
-- name: ExamPrepListUnitModulesByUnit :many
|
|
WITH module_counts AS (
|
|
SELECT
|
|
m.id AS module_id,
|
|
COUNT(DISTINCT l.id)::BIGINT AS lessons_count,
|
|
COUNT(DISTINCT p.id)::BIGINT AS practices_count
|
|
FROM exam_prep.unit_modules m
|
|
LEFT JOIN exam_prep.unit_module_lessons l ON l.unit_module_id = m.id
|
|
LEFT JOIN exam_prep.lesson_practices p ON p.unit_module_lesson_id = l.id
|
|
GROUP BY m.id
|
|
)
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
m.id,
|
|
m.unit_id,
|
|
m.name,
|
|
m.description,
|
|
m.thumbnail,
|
|
m.icon,
|
|
m.sort_order,
|
|
COALESCE(mc.lessons_count, 0)::BIGINT AS lessons_count,
|
|
COALESCE(mc.practices_count, 0)::BIGINT AS practices_count,
|
|
(COALESCE(mc.practices_count, 0)::BIGINT > 0) AS has_practice,
|
|
m.created_at,
|
|
m.updated_at
|
|
FROM exam_prep.unit_modules m
|
|
LEFT JOIN module_counts mc ON mc.module_id = m.id
|
|
WHERE
|
|
m.unit_id = $1
|
|
ORDER BY
|
|
m.sort_order ASC,
|
|
m.id ASC
|
|
LIMIT $2
|
|
OFFSET $3;
|
|
|
|
-- name: ExamPrepUpdateUnitModule :one
|
|
UPDATE exam_prep.unit_modules
|
|
SET
|
|
name = coalesce(sqlc.narg('name')::varchar, name),
|
|
description = coalesce(sqlc.narg('description')::text, description),
|
|
thumbnail = coalesce(sqlc.narg('thumbnail')::text, thumbnail),
|
|
icon = coalesce(sqlc.narg('icon')::text, icon),
|
|
sort_order = coalesce(sqlc.narg('sort_order')::int, sort_order),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = sqlc.arg('id')
|
|
RETURNING
|
|
*;
|
|
|
|
-- name: ExamPrepDeleteUnitModule :exec
|
|
DELETE FROM exam_prep.unit_modules
|
|
WHERE id = $1;
|