Expose publish_status on create/update, filter learner-facing lists and gates, and add migration 000060. Co-authored-by: Cursor <cursoragent@cursor.com>
389 lines
12 KiB
Go
389 lines
12 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: user_recent_activity.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const ListUserCourseCompletionsRecentActivity = `-- name: ListUserCourseCompletionsRecentActivity :many
|
|
SELECT
|
|
crf.completed_at AS occurred_at,
|
|
c.id AS course_id,
|
|
c.name AS course_name,
|
|
p.id AS program_id,
|
|
p.name AS program_name
|
|
FROM
|
|
lms_user_course_progress crf
|
|
INNER JOIN courses c ON c.id = crf.course_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
crf.user_id = $1
|
|
`
|
|
|
|
type ListUserCourseCompletionsRecentActivityRow struct {
|
|
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
|
CourseID int64 `json:"course_id"`
|
|
CourseName string `json:"course_name"`
|
|
ProgramID int64 `json:"program_id"`
|
|
ProgramName string `json:"program_name"`
|
|
}
|
|
|
|
func (q *Queries) ListUserCourseCompletionsRecentActivity(ctx context.Context, userID int64) ([]ListUserCourseCompletionsRecentActivityRow, error) {
|
|
rows, err := q.db.Query(ctx, ListUserCourseCompletionsRecentActivity, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListUserCourseCompletionsRecentActivityRow
|
|
for rows.Next() {
|
|
var i ListUserCourseCompletionsRecentActivityRow
|
|
if err := rows.Scan(
|
|
&i.OccurredAt,
|
|
&i.CourseID,
|
|
&i.CourseName,
|
|
&i.ProgramID,
|
|
&i.ProgramName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListUserLessonCompletionsRecentActivity = `-- name: ListUserLessonCompletionsRecentActivity :many
|
|
|
|
SELECT
|
|
ulp.completed_at AS occurred_at,
|
|
l.id AS lesson_id,
|
|
l.title AS lesson_title,
|
|
m.id AS module_id,
|
|
m.name AS module_name,
|
|
m.sort_order AS module_sort_order,
|
|
c.id AS course_id,
|
|
c.name AS course_name,
|
|
p.id AS program_id,
|
|
p.name AS program_name
|
|
FROM
|
|
lms_user_lesson_progress ulp
|
|
INNER JOIN lessons l ON l.id = ulp.lesson_id
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
AND c.program_id = m.program_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
ulp.user_id = $1
|
|
`
|
|
|
|
type ListUserLessonCompletionsRecentActivityRow struct {
|
|
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
|
LessonID int64 `json:"lesson_id"`
|
|
LessonTitle string `json:"lesson_title"`
|
|
ModuleID int64 `json:"module_id"`
|
|
ModuleName string `json:"module_name"`
|
|
ModuleSortOrder int32 `json:"module_sort_order"`
|
|
CourseID int64 `json:"course_id"`
|
|
CourseName string `json:"course_name"`
|
|
ProgramID int64 `json:"program_id"`
|
|
ProgramName string `json:"program_name"`
|
|
}
|
|
|
|
// Recent activity feed: LMS completion milestones (chronological merge in application code).
|
|
func (q *Queries) ListUserLessonCompletionsRecentActivity(ctx context.Context, userID int64) ([]ListUserLessonCompletionsRecentActivityRow, error) {
|
|
rows, err := q.db.Query(ctx, ListUserLessonCompletionsRecentActivity, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListUserLessonCompletionsRecentActivityRow
|
|
for rows.Next() {
|
|
var i ListUserLessonCompletionsRecentActivityRow
|
|
if err := rows.Scan(
|
|
&i.OccurredAt,
|
|
&i.LessonID,
|
|
&i.LessonTitle,
|
|
&i.ModuleID,
|
|
&i.ModuleName,
|
|
&i.ModuleSortOrder,
|
|
&i.CourseID,
|
|
&i.CourseName,
|
|
&i.ProgramID,
|
|
&i.ProgramName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListUserModuleCompletionsRecentActivity = `-- name: ListUserModuleCompletionsRecentActivity :many
|
|
SELECT
|
|
mrf.completed_at AS occurred_at,
|
|
m.id AS module_id,
|
|
m.name AS module_name,
|
|
m.sort_order AS module_sort_order,
|
|
c.id AS course_id,
|
|
c.name AS course_name,
|
|
p.id AS program_id,
|
|
p.name AS program_name
|
|
FROM
|
|
lms_user_module_progress mrf
|
|
INNER JOIN modules m ON m.id = mrf.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
AND c.program_id = m.program_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
mrf.user_id = $1
|
|
`
|
|
|
|
type ListUserModuleCompletionsRecentActivityRow struct {
|
|
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
|
ModuleID int64 `json:"module_id"`
|
|
ModuleName string `json:"module_name"`
|
|
ModuleSortOrder int32 `json:"module_sort_order"`
|
|
CourseID int64 `json:"course_id"`
|
|
CourseName string `json:"course_name"`
|
|
ProgramID int64 `json:"program_id"`
|
|
ProgramName string `json:"program_name"`
|
|
}
|
|
|
|
func (q *Queries) ListUserModuleCompletionsRecentActivity(ctx context.Context, userID int64) ([]ListUserModuleCompletionsRecentActivityRow, error) {
|
|
rows, err := q.db.Query(ctx, ListUserModuleCompletionsRecentActivity, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListUserModuleCompletionsRecentActivityRow
|
|
for rows.Next() {
|
|
var i ListUserModuleCompletionsRecentActivityRow
|
|
if err := rows.Scan(
|
|
&i.OccurredAt,
|
|
&i.ModuleID,
|
|
&i.ModuleName,
|
|
&i.ModuleSortOrder,
|
|
&i.CourseID,
|
|
&i.CourseName,
|
|
&i.ProgramID,
|
|
&i.ProgramName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListUserPracticeCompletionsRecentActivity = `-- name: ListUserPracticeCompletionsRecentActivity :many
|
|
SELECT
|
|
x.occurred_at,
|
|
x.scope,
|
|
x.lms_practice_id,
|
|
x.practice_title,
|
|
COALESCE(x.lesson_id, 0)::BIGINT AS lesson_id,
|
|
COALESCE(x.lesson_title, '')::TEXT AS lesson_title,
|
|
COALESCE(x.module_id, 0)::BIGINT AS module_id,
|
|
COALESCE(x.module_name, '')::TEXT AS module_name,
|
|
COALESCE(x.module_sort_order, 0)::INT AS module_sort_order,
|
|
x.course_id,
|
|
x.course_name,
|
|
x.program_id,
|
|
x.program_name
|
|
FROM (
|
|
SELECT
|
|
upp.completed_at AS occurred_at,
|
|
'lesson'::TEXT AS scope,
|
|
lp.id AS lms_practice_id,
|
|
lp.title AS practice_title,
|
|
l.id AS lesson_id,
|
|
l.title AS lesson_title,
|
|
m.id AS module_id,
|
|
m.name AS module_name,
|
|
m.sort_order AS module_sort_order,
|
|
c.id AS course_id,
|
|
c.name AS course_name,
|
|
p.id AS program_id,
|
|
p.name AS program_name
|
|
FROM
|
|
user_practice_progress upp
|
|
INNER JOIN lms_practices lp ON lp.question_set_id = upp.question_set_id
|
|
AND lp.lesson_id IS NOT NULL
|
|
AND lp.publish_status = 'PUBLISHED'
|
|
INNER JOIN question_sets qs ON qs.id = upp.question_set_id
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
INNER JOIN lessons l ON l.id = lp.lesson_id
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
AND c.program_id = m.program_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
upp.user_id = $1
|
|
AND upp.completed_at IS NOT NULL
|
|
UNION ALL
|
|
SELECT
|
|
upp.completed_at,
|
|
'module'::TEXT,
|
|
lp.id,
|
|
lp.title,
|
|
NULL::BIGINT,
|
|
NULL::VARCHAR,
|
|
m.id,
|
|
m.name,
|
|
m.sort_order,
|
|
c.id,
|
|
c.name,
|
|
p.id,
|
|
p.name
|
|
FROM
|
|
user_practice_progress upp
|
|
INNER JOIN lms_practices lp ON lp.question_set_id = upp.question_set_id
|
|
AND lp.module_id IS NOT NULL
|
|
AND lp.lesson_id IS NULL
|
|
AND lp.publish_status = 'PUBLISHED'
|
|
INNER JOIN question_sets qs ON qs.id = upp.question_set_id
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
INNER JOIN modules m ON m.id = lp.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
AND c.program_id = m.program_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
upp.user_id = $1
|
|
AND upp.completed_at IS NOT NULL
|
|
UNION ALL
|
|
SELECT
|
|
upp.completed_at,
|
|
'course'::TEXT,
|
|
lp.id,
|
|
lp.title,
|
|
NULL::BIGINT,
|
|
NULL::VARCHAR,
|
|
NULL::BIGINT,
|
|
NULL::VARCHAR,
|
|
NULL::INT,
|
|
c.id,
|
|
c.name,
|
|
p.id,
|
|
p.name
|
|
FROM
|
|
user_practice_progress upp
|
|
INNER JOIN lms_practices lp ON lp.question_set_id = upp.question_set_id
|
|
AND lp.course_id IS NOT NULL
|
|
AND lp.module_id IS NULL
|
|
AND lp.lesson_id IS NULL
|
|
AND lp.publish_status = 'PUBLISHED'
|
|
INNER JOIN question_sets qs ON qs.id = upp.question_set_id
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.status = 'PUBLISHED'
|
|
INNER JOIN courses c ON c.id = lp.course_id
|
|
INNER JOIN programs p ON p.id = c.program_id
|
|
WHERE
|
|
upp.user_id = $1
|
|
AND upp.completed_at IS NOT NULL
|
|
) AS x
|
|
`
|
|
|
|
type ListUserPracticeCompletionsRecentActivityRow struct {
|
|
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
|
Scope string `json:"scope"`
|
|
LmsPracticeID int64 `json:"lms_practice_id"`
|
|
PracticeTitle string `json:"practice_title"`
|
|
LessonID int64 `json:"lesson_id"`
|
|
LessonTitle string `json:"lesson_title"`
|
|
ModuleID int64 `json:"module_id"`
|
|
ModuleName string `json:"module_name"`
|
|
ModuleSortOrder int32 `json:"module_sort_order"`
|
|
CourseID int64 `json:"course_id"`
|
|
CourseName string `json:"course_name"`
|
|
ProgramID int64 `json:"program_id"`
|
|
ProgramName string `json:"program_name"`
|
|
}
|
|
|
|
func (q *Queries) ListUserPracticeCompletionsRecentActivity(ctx context.Context, userID int64) ([]ListUserPracticeCompletionsRecentActivityRow, error) {
|
|
rows, err := q.db.Query(ctx, ListUserPracticeCompletionsRecentActivity, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListUserPracticeCompletionsRecentActivityRow
|
|
for rows.Next() {
|
|
var i ListUserPracticeCompletionsRecentActivityRow
|
|
if err := rows.Scan(
|
|
&i.OccurredAt,
|
|
&i.Scope,
|
|
&i.LmsPracticeID,
|
|
&i.PracticeTitle,
|
|
&i.LessonID,
|
|
&i.LessonTitle,
|
|
&i.ModuleID,
|
|
&i.ModuleName,
|
|
&i.ModuleSortOrder,
|
|
&i.CourseID,
|
|
&i.CourseName,
|
|
&i.ProgramID,
|
|
&i.ProgramName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListUserProgramCompletionsRecentActivity = `-- name: ListUserProgramCompletionsRecentActivity :many
|
|
SELECT
|
|
prf.completed_at AS occurred_at,
|
|
p.id AS program_id,
|
|
p.name AS program_name
|
|
FROM
|
|
lms_user_program_progress prf
|
|
INNER JOIN programs p ON p.id = prf.program_id
|
|
WHERE
|
|
prf.user_id = $1
|
|
`
|
|
|
|
type ListUserProgramCompletionsRecentActivityRow struct {
|
|
OccurredAt pgtype.Timestamptz `json:"occurred_at"`
|
|
ProgramID int64 `json:"program_id"`
|
|
ProgramName string `json:"program_name"`
|
|
}
|
|
|
|
func (q *Queries) ListUserProgramCompletionsRecentActivity(ctx context.Context, userID int64) ([]ListUserProgramCompletionsRecentActivityRow, error) {
|
|
rows, err := q.db.Query(ctx, ListUserProgramCompletionsRecentActivity, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListUserProgramCompletionsRecentActivityRow
|
|
for rows.Next() {
|
|
var i ListUserProgramCompletionsRecentActivityRow
|
|
if err := rows.Scan(&i.OccurredAt, &i.ProgramID, &i.ProgramName); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|