Add migration 000109, require parent context on complete, and update progress queries and LMS rollups. Co-authored-by: Cursor <cursoragent@cursor.com>
776 lines
25 KiB
Go
776 lines
25 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: exam_prep_progress.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CountPublishedDirectExamPrepPracticesInCatalogCourse = `-- 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'
|
|
`
|
|
|
|
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
|
|
}
|
|
|
|
const CountPublishedExamPrepPracticesInLesson = `-- name: CountPublishedExamPrepPracticesInLesson :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 = '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, parentID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInLesson, parentID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountPublishedExamPrepPracticesInModule = `-- name: CountPublishedExamPrepPracticesInModule :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 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
|
|
AND l.publish_status = 'PUBLISHED'
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
AND p.publish_status = 'PUBLISHED'
|
|
`
|
|
|
|
func (q *Queries) CountPublishedExamPrepPracticesInModule(ctx context.Context, unitModuleID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInModule, unitModuleID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountPublishedExamPrepPracticesInUnit = `-- name: CountPublishedExamPrepPracticesInUnit :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
|
|
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
|
|
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, parentID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountPublishedExamPrepPracticesInUnit, parentID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedPublishedDirectExamPrepPracticesInCatalogCourse = `-- 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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
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'
|
|
`
|
|
|
|
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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
WHERE
|
|
pp.parent_kind = 'UNIT'
|
|
AND pp.parent_id = $1
|
|
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(*)::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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
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'
|
|
)
|
|
)
|
|
)
|
|
`
|
|
|
|
type CountUserCompletedPublishedExamPrepPracticesInCatalogCourseParams struct {
|
|
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.ParentID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedPublishedExamPrepPracticesInLesson = `-- name: CountUserCompletedPublishedExamPrepPracticesInLesson :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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
WHERE
|
|
pp.parent_kind = 'LESSON'
|
|
AND pp.parent_id = $1
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
AND p.publish_status = 'PUBLISHED'
|
|
`
|
|
|
|
type CountUserCompletedPublishedExamPrepPracticesInLessonParams struct {
|
|
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.ParentID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedPublishedExamPrepPracticesInModule = `-- name: CountUserCompletedPublishedExamPrepPracticesInModule :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 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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
WHERE
|
|
l.unit_module_id = $1
|
|
AND l.publish_status = 'PUBLISHED'
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
AND p.publish_status = 'PUBLISHED'
|
|
`
|
|
|
|
type CountUserCompletedPublishedExamPrepPracticesInModuleParams struct {
|
|
UnitModuleID int64 `json:"unit_module_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedPublishedExamPrepPracticesInModule(ctx context.Context, arg CountUserCompletedPublishedExamPrepPracticesInModuleParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedPublishedExamPrepPracticesInModule, arg.UnitModuleID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedPublishedExamPrepPracticesInUnit = `-- name: CountUserCompletedPublishedExamPrepPracticesInUnit :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
|
|
AND upp.user_id = $2
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = pp.parent_kind
|
|
AND upp.parent_id = pp.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
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
|
|
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 {
|
|
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.ParentID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const GetFirstIncompletePreviousExamPrepPractice = `-- name: GetFirstIncompletePreviousExamPrepPractice :one
|
|
WITH target AS (
|
|
SELECT
|
|
lp.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
|
|
AND pp.parent_kind = $3::VARCHAR
|
|
AND pp.parent_id = $4::BIGINT
|
|
AND lp.publish_status = 'PUBLISHED'
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
),
|
|
candidates AS (
|
|
SELECT
|
|
lp.id,
|
|
lp.title,
|
|
lp.question_set_id,
|
|
lp.created_at,
|
|
pp.parent_kind,
|
|
pp.parent_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
|
|
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'
|
|
AND qs.status = 'PUBLISHED'
|
|
AND (
|
|
lp.created_at < t.created_at
|
|
OR (
|
|
lp.created_at = t.created_at
|
|
AND lp.id < t.id
|
|
)
|
|
)
|
|
)
|
|
SELECT
|
|
c.id,
|
|
c.title,
|
|
c.question_set_id
|
|
FROM
|
|
candidates c
|
|
LEFT JOIN user_practice_progress upp ON upp.question_set_id = c.question_set_id
|
|
AND upp.user_id = $1::BIGINT
|
|
AND upp.content_domain = 'EXAM_PREP'
|
|
AND upp.parent_kind = c.parent_kind
|
|
AND upp.parent_id = c.parent_id
|
|
AND upp.completed_at IS NOT NULL
|
|
WHERE
|
|
upp.id IS NULL
|
|
ORDER BY
|
|
c.created_at ASC,
|
|
c.id ASC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetFirstIncompletePreviousExamPrepPracticeParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
ParentKind string `json:"parent_kind"`
|
|
ParentID int64 `json:"parent_id"`
|
|
}
|
|
|
|
type GetFirstIncompletePreviousExamPrepPracticeRow struct {
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
}
|
|
|
|
func (q *Queries) GetFirstIncompletePreviousExamPrepPractice(ctx context.Context, arg GetFirstIncompletePreviousExamPrepPracticeParams) (GetFirstIncompletePreviousExamPrepPracticeRow, error) {
|
|
row := q.db.QueryRow(ctx, GetFirstIncompletePreviousExamPrepPractice,
|
|
arg.UserID,
|
|
arg.QuestionSetID,
|
|
arg.ParentKind,
|
|
arg.ParentID,
|
|
)
|
|
var i GetFirstIncompletePreviousExamPrepPracticeRow
|
|
err := row.Scan(&i.ID, &i.Title, &i.QuestionSetID)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousExamPrepCatalogCourse = `-- name: GetPreviousExamPrepCatalogCourse :one
|
|
SELECT
|
|
cc2.id,
|
|
cc2.name,
|
|
cc2.description,
|
|
cc2.thumbnail,
|
|
cc2.sort_order,
|
|
cc2.category,
|
|
cc2.publish_status,
|
|
cc2.access_tier,
|
|
cc2.created_at,
|
|
cc2.updated_at
|
|
FROM
|
|
exam_prep.catalog_courses AS cc1
|
|
INNER JOIN exam_prep.catalog_courses AS cc2 ON cc2.category = cc1.category
|
|
AND cc2.publish_status = 'PUBLISHED'
|
|
AND (
|
|
cc2.sort_order < cc1.sort_order
|
|
OR (
|
|
cc2.sort_order = cc1.sort_order
|
|
AND cc2.id < cc1.id
|
|
)
|
|
)
|
|
WHERE
|
|
cc1.id = $1
|
|
ORDER BY
|
|
cc2.sort_order DESC,
|
|
cc2.id DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetPreviousExamPrepCatalogCourseRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
Category string `json:"category"`
|
|
PublishStatus string `json:"publish_status"`
|
|
AccessTier string `json:"access_tier"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
// Immediate predecessor by sort_order within the same category (gaps in sort_order are allowed).
|
|
func (q *Queries) GetPreviousExamPrepCatalogCourse(ctx context.Context, id int64) (GetPreviousExamPrepCatalogCourseRow, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousExamPrepCatalogCourse, id)
|
|
var i GetPreviousExamPrepCatalogCourseRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.SortOrder,
|
|
&i.Category,
|
|
&i.PublishStatus,
|
|
&i.AccessTier,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousExamPrepLessonInModule = `-- name: GetPreviousExamPrepLessonInModule :one
|
|
SELECT
|
|
l2.id,
|
|
l2.unit_module_id,
|
|
l2.title,
|
|
l2.video_url,
|
|
l2.thumbnail,
|
|
l2.description,
|
|
l2.sort_order,
|
|
l2.publish_status,
|
|
l2.access_tier,
|
|
l2.created_at,
|
|
l2.updated_at
|
|
FROM
|
|
exam_prep.unit_module_lessons AS l1
|
|
INNER JOIN exam_prep.unit_module_lessons AS l2 ON l2.unit_module_id = l1.unit_module_id
|
|
AND l2.publish_status = 'PUBLISHED'
|
|
AND l1.publish_status = 'PUBLISHED'
|
|
AND (
|
|
l2.sort_order < l1.sort_order
|
|
OR (
|
|
l2.sort_order = l1.sort_order
|
|
AND l2.id < l1.id
|
|
)
|
|
)
|
|
WHERE
|
|
l1.id = $1
|
|
ORDER BY
|
|
l2.sort_order DESC,
|
|
l2.id DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetPreviousExamPrepLessonInModuleRow struct {
|
|
ID int64 `json:"id"`
|
|
UnitModuleID int64 `json:"unit_module_id"`
|
|
Title string `json:"title"`
|
|
VideoUrl pgtype.Text `json:"video_url"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Description pgtype.Text `json:"description"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
PublishStatus string `json:"publish_status"`
|
|
AccessTier string `json:"access_tier"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetPreviousExamPrepLessonInModule(ctx context.Context, id int64) (GetPreviousExamPrepLessonInModuleRow, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousExamPrepLessonInModule, id)
|
|
var i GetPreviousExamPrepLessonInModuleRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UnitModuleID,
|
|
&i.Title,
|
|
&i.VideoUrl,
|
|
&i.Thumbnail,
|
|
&i.Description,
|
|
&i.SortOrder,
|
|
&i.PublishStatus,
|
|
&i.AccessTier,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousExamPrepModuleInUnit = `-- name: GetPreviousExamPrepModuleInUnit :one
|
|
SELECT
|
|
m2.id,
|
|
m2.unit_id,
|
|
m2.name,
|
|
m2.description,
|
|
m2.thumbnail,
|
|
m2.icon,
|
|
m2.sort_order,
|
|
m2.publish_status,
|
|
m2.access_tier,
|
|
m2.created_at,
|
|
m2.updated_at
|
|
FROM
|
|
exam_prep.unit_modules AS m1
|
|
INNER JOIN exam_prep.unit_modules AS m2 ON m2.unit_id = m1.unit_id
|
|
AND m2.publish_status = 'PUBLISHED'
|
|
AND (
|
|
m2.sort_order < m1.sort_order
|
|
OR (
|
|
m2.sort_order = m1.sort_order
|
|
AND m2.id < m1.id
|
|
)
|
|
)
|
|
WHERE
|
|
m1.id = $1
|
|
ORDER BY
|
|
m2.sort_order DESC,
|
|
m2.id DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetPreviousExamPrepModuleInUnitRow struct {
|
|
ID int64 `json:"id"`
|
|
UnitID int64 `json:"unit_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
PublishStatus string `json:"publish_status"`
|
|
AccessTier string `json:"access_tier"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetPreviousExamPrepModuleInUnit(ctx context.Context, id int64) (GetPreviousExamPrepModuleInUnitRow, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousExamPrepModuleInUnit, id)
|
|
var i GetPreviousExamPrepModuleInUnitRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UnitID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.PublishStatus,
|
|
&i.AccessTier,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousExamPrepUnitInCatalogCourse = `-- name: GetPreviousExamPrepUnitInCatalogCourse :one
|
|
SELECT
|
|
u2.id,
|
|
u2.catalog_course_id,
|
|
u2.name,
|
|
u2.description,
|
|
u2.thumbnail,
|
|
u2.sort_order,
|
|
u2.publish_status,
|
|
u2.access_tier,
|
|
u2.created_at,
|
|
u2.updated_at
|
|
FROM
|
|
exam_prep.units AS u1
|
|
INNER JOIN exam_prep.units AS u2 ON u2.catalog_course_id = u1.catalog_course_id
|
|
AND u2.publish_status = 'PUBLISHED'
|
|
AND (
|
|
u2.sort_order < u1.sort_order
|
|
OR (
|
|
u2.sort_order = u1.sort_order
|
|
AND u2.id < u1.id
|
|
)
|
|
)
|
|
WHERE
|
|
u1.id = $1
|
|
ORDER BY
|
|
u2.sort_order DESC,
|
|
u2.id DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetPreviousExamPrepUnitInCatalogCourseRow struct {
|
|
ID int64 `json:"id"`
|
|
CatalogCourseID int64 `json:"catalog_course_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
PublishStatus string `json:"publish_status"`
|
|
AccessTier string `json:"access_tier"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetPreviousExamPrepUnitInCatalogCourse(ctx context.Context, id int64) (GetPreviousExamPrepUnitInCatalogCourseRow, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousExamPrepUnitInCatalogCourse, id)
|
|
var i GetPreviousExamPrepUnitInCatalogCourseRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CatalogCourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.SortOrder,
|
|
&i.PublishStatus,
|
|
&i.AccessTier,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|