Replace rename-based lesson migration with additive sub_module_lessons creation, preserve sub_module_practices as its own model, and enforce QUIZ/PRACTICE filtering in hierarchy reads to prevent cross-mixing. Made-with: Cursor
769 lines
19 KiB
Go
769 lines
19 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: hierarchy.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const AttachQuestionSetLessonToSubModule = `-- name: AttachQuestionSetLessonToSubModule :one
|
|
INSERT INTO sub_module_lessons (
|
|
sub_module_id,
|
|
question_set_id,
|
|
intro_video_url,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, COALESCE($4, 0), COALESCE($5, TRUE))
|
|
RETURNING id, sub_module_id, question_set_id, intro_video_url, display_order, is_active, created_at
|
|
`
|
|
|
|
type AttachQuestionSetLessonToSubModuleParams struct {
|
|
SubModuleID int64 `json:"sub_module_id"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
IntroVideoUrl pgtype.Text `json:"intro_video_url"`
|
|
Column4 interface{} `json:"column_4"`
|
|
Column5 interface{} `json:"column_5"`
|
|
}
|
|
|
|
func (q *Queries) AttachQuestionSetLessonToSubModule(ctx context.Context, arg AttachQuestionSetLessonToSubModuleParams) (SubModuleLesson, error) {
|
|
row := q.db.QueryRow(ctx, AttachQuestionSetLessonToSubModule,
|
|
arg.SubModuleID,
|
|
arg.QuestionSetID,
|
|
arg.IntroVideoUrl,
|
|
arg.Column4,
|
|
arg.Column5,
|
|
)
|
|
var i SubModuleLesson
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.QuestionSetID,
|
|
&i.IntroVideoUrl,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateCourseSubCategory = `-- name: CreateCourseSubCategory :one
|
|
INSERT INTO course_sub_categories (
|
|
category_id,
|
|
name,
|
|
description,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, COALESCE($4, 0), COALESCE($5, TRUE))
|
|
RETURNING id, category_id, name, description, is_active, display_order, created_at
|
|
`
|
|
|
|
type CreateCourseSubCategoryParams struct {
|
|
CategoryID int64 `json:"category_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Column4 interface{} `json:"column_4"`
|
|
Column5 interface{} `json:"column_5"`
|
|
}
|
|
|
|
func (q *Queries) CreateCourseSubCategory(ctx context.Context, arg CreateCourseSubCategoryParams) (CourseSubCategory, error) {
|
|
row := q.db.QueryRow(ctx, CreateCourseSubCategory,
|
|
arg.CategoryID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Column4,
|
|
arg.Column5,
|
|
)
|
|
var i CourseSubCategory
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.DisplayOrder,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateLevel = `-- name: CreateLevel :one
|
|
INSERT INTO levels (
|
|
course_id,
|
|
cefr_level,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, COALESCE($3, 0), COALESCE($4, TRUE))
|
|
RETURNING id, course_id, cefr_level, display_order, is_active, created_at
|
|
`
|
|
|
|
type CreateLevelParams struct {
|
|
CourseID int64 `json:"course_id"`
|
|
CefrLevel string `json:"cefr_level"`
|
|
Column3 interface{} `json:"column_3"`
|
|
Column4 interface{} `json:"column_4"`
|
|
}
|
|
|
|
func (q *Queries) CreateLevel(ctx context.Context, arg CreateLevelParams) (Level, error) {
|
|
row := q.db.QueryRow(ctx, CreateLevel,
|
|
arg.CourseID,
|
|
arg.CefrLevel,
|
|
arg.Column3,
|
|
arg.Column4,
|
|
)
|
|
var i Level
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.CefrLevel,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateModule = `-- name: CreateModule :one
|
|
INSERT INTO modules (
|
|
level_id,
|
|
title,
|
|
description,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, COALESCE($4, 0), COALESCE($5, TRUE))
|
|
RETURNING id, level_id, title, description, display_order, is_active, created_at
|
|
`
|
|
|
|
type CreateModuleParams struct {
|
|
LevelID int64 `json:"level_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Column4 interface{} `json:"column_4"`
|
|
Column5 interface{} `json:"column_5"`
|
|
}
|
|
|
|
func (q *Queries) CreateModule(ctx context.Context, arg CreateModuleParams) (Module, error) {
|
|
row := q.db.QueryRow(ctx, CreateModule,
|
|
arg.LevelID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Column4,
|
|
arg.Column5,
|
|
)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateSubModule = `-- name: CreateSubModule :one
|
|
INSERT INTO sub_modules (
|
|
module_id,
|
|
title,
|
|
description,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, COALESCE($4, 0), COALESCE($5, TRUE))
|
|
RETURNING id, module_id, title, description, display_order, is_active, created_at, legacy_sub_course_id
|
|
`
|
|
|
|
type CreateSubModuleParams struct {
|
|
ModuleID int64 `json:"module_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Column4 interface{} `json:"column_4"`
|
|
Column5 interface{} `json:"column_5"`
|
|
}
|
|
|
|
func (q *Queries) CreateSubModule(ctx context.Context, arg CreateSubModuleParams) (SubModule, error) {
|
|
row := q.db.QueryRow(ctx, CreateSubModule,
|
|
arg.ModuleID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Column4,
|
|
arg.Column5,
|
|
)
|
|
var i SubModule
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.LegacySubCourseID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateSubModulePractice = `-- name: CreateSubModulePractice :one
|
|
INSERT INTO sub_module_practices (
|
|
sub_module_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
intro_video_url,
|
|
question_set_id,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, COALESCE($7, 0), COALESCE($8, TRUE))
|
|
RETURNING id, sub_module_id, title, description, thumbnail, intro_video_url, question_set_id, display_order, is_active, created_at
|
|
`
|
|
|
|
type CreateSubModulePracticeParams struct {
|
|
SubModuleID int64 `json:"sub_module_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IntroVideoUrl pgtype.Text `json:"intro_video_url"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
Column7 interface{} `json:"column_7"`
|
|
Column8 interface{} `json:"column_8"`
|
|
}
|
|
|
|
func (q *Queries) CreateSubModulePractice(ctx context.Context, arg CreateSubModulePracticeParams) (SubModulePractice, error) {
|
|
row := q.db.QueryRow(ctx, CreateSubModulePractice,
|
|
arg.SubModuleID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.IntroVideoUrl,
|
|
arg.QuestionSetID,
|
|
arg.Column7,
|
|
arg.Column8,
|
|
)
|
|
var i SubModulePractice
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.IntroVideoUrl,
|
|
&i.QuestionSetID,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateSubModuleVideo = `-- name: CreateSubModuleVideo :one
|
|
INSERT INTO sub_module_videos (
|
|
sub_module_id,
|
|
title,
|
|
description,
|
|
video_url,
|
|
duration,
|
|
resolution,
|
|
is_published,
|
|
publish_date,
|
|
visibility,
|
|
instructor_id,
|
|
thumbnail,
|
|
display_order,
|
|
status,
|
|
vimeo_id,
|
|
vimeo_embed_url,
|
|
vimeo_player_html,
|
|
vimeo_status,
|
|
video_host_provider
|
|
)
|
|
VALUES (
|
|
$1, $2, $3, $4, $5, $6,
|
|
COALESCE($7, FALSE), $8, $9, $10, $11,
|
|
COALESCE($12, 0), COALESCE($13, 'DRAFT'),
|
|
$14, $15, $16, $17, COALESCE($18, 'DIRECT')
|
|
)
|
|
RETURNING id, sub_module_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider, created_at
|
|
`
|
|
|
|
type CreateSubModuleVideoParams struct {
|
|
SubModuleID int64 `json:"sub_module_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
VideoUrl string `json:"video_url"`
|
|
Duration pgtype.Int4 `json:"duration"`
|
|
Resolution pgtype.Text `json:"resolution"`
|
|
Column7 interface{} `json:"column_7"`
|
|
PublishDate pgtype.Timestamptz `json:"publish_date"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
InstructorID pgtype.Text `json:"instructor_id"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Column12 interface{} `json:"column_12"`
|
|
Column13 interface{} `json:"column_13"`
|
|
VimeoID pgtype.Text `json:"vimeo_id"`
|
|
VimeoEmbedUrl pgtype.Text `json:"vimeo_embed_url"`
|
|
VimeoPlayerHtml pgtype.Text `json:"vimeo_player_html"`
|
|
VimeoStatus pgtype.Text `json:"vimeo_status"`
|
|
Column18 interface{} `json:"column_18"`
|
|
}
|
|
|
|
func (q *Queries) CreateSubModuleVideo(ctx context.Context, arg CreateSubModuleVideoParams) (SubModuleVideo, error) {
|
|
row := q.db.QueryRow(ctx, CreateSubModuleVideo,
|
|
arg.SubModuleID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.VideoUrl,
|
|
arg.Duration,
|
|
arg.Resolution,
|
|
arg.Column7,
|
|
arg.PublishDate,
|
|
arg.Visibility,
|
|
arg.InstructorID,
|
|
arg.Thumbnail,
|
|
arg.Column12,
|
|
arg.Column13,
|
|
arg.VimeoID,
|
|
arg.VimeoEmbedUrl,
|
|
arg.VimeoPlayerHtml,
|
|
arg.VimeoStatus,
|
|
arg.Column18,
|
|
)
|
|
var i SubModuleVideo
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.VideoUrl,
|
|
&i.Duration,
|
|
&i.Resolution,
|
|
&i.IsPublished,
|
|
&i.PublishDate,
|
|
&i.Visibility,
|
|
&i.InstructorID,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.Status,
|
|
&i.VimeoID,
|
|
&i.VimeoEmbedUrl,
|
|
&i.VimeoPlayerHtml,
|
|
&i.VimeoStatus,
|
|
&i.VideoHostProvider,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetCoursesWithHierarchy = `-- name: GetCoursesWithHierarchy :many
|
|
SELECT
|
|
cc.id AS category_id,
|
|
cc.name AS category_name,
|
|
csc.id AS sub_category_id,
|
|
csc.name AS sub_category_name,
|
|
c.id AS course_id,
|
|
c.title AS course_title
|
|
FROM course_categories cc
|
|
LEFT JOIN course_sub_categories csc ON csc.category_id = cc.id AND csc.is_active = TRUE
|
|
LEFT JOIN courses c ON c.sub_category_id = csc.id AND c.is_active = TRUE
|
|
WHERE cc.is_active = TRUE
|
|
ORDER BY cc.id, csc.display_order, csc.id, c.id
|
|
`
|
|
|
|
type GetCoursesWithHierarchyRow struct {
|
|
CategoryID int64 `json:"category_id"`
|
|
CategoryName string `json:"category_name"`
|
|
SubCategoryID pgtype.Int8 `json:"sub_category_id"`
|
|
SubCategoryName pgtype.Text `json:"sub_category_name"`
|
|
CourseID pgtype.Int8 `json:"course_id"`
|
|
CourseTitle pgtype.Text `json:"course_title"`
|
|
}
|
|
|
|
func (q *Queries) GetCoursesWithHierarchy(ctx context.Context) ([]GetCoursesWithHierarchyRow, error) {
|
|
rows, err := q.db.Query(ctx, GetCoursesWithHierarchy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetCoursesWithHierarchyRow
|
|
for rows.Next() {
|
|
var i GetCoursesWithHierarchyRow
|
|
if err := rows.Scan(
|
|
&i.CategoryID,
|
|
&i.CategoryName,
|
|
&i.SubCategoryID,
|
|
&i.SubCategoryName,
|
|
&i.CourseID,
|
|
&i.CourseTitle,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetFullHierarchyByCourseID = `-- name: GetFullHierarchyByCourseID :many
|
|
SELECT
|
|
c.id AS course_id,
|
|
c.title AS course_title,
|
|
l.id AS level_id,
|
|
l.cefr_level,
|
|
m.id AS module_id,
|
|
m.title AS module_title,
|
|
sm.id AS sub_module_id,
|
|
sm.title AS sub_module_title
|
|
FROM courses c
|
|
LEFT JOIN levels l ON l.course_id = c.id AND l.is_active = TRUE
|
|
LEFT JOIN modules m ON m.level_id = l.id AND m.is_active = TRUE
|
|
LEFT JOIN sub_modules sm ON sm.module_id = m.id AND sm.is_active = TRUE
|
|
WHERE c.id = $1
|
|
ORDER BY l.display_order, l.id, m.display_order, m.id, sm.display_order, sm.id
|
|
`
|
|
|
|
type GetFullHierarchyByCourseIDRow struct {
|
|
CourseID int64 `json:"course_id"`
|
|
CourseTitle string `json:"course_title"`
|
|
LevelID pgtype.Int8 `json:"level_id"`
|
|
CefrLevel pgtype.Text `json:"cefr_level"`
|
|
ModuleID pgtype.Int8 `json:"module_id"`
|
|
ModuleTitle pgtype.Text `json:"module_title"`
|
|
SubModuleID pgtype.Int8 `json:"sub_module_id"`
|
|
SubModuleTitle pgtype.Text `json:"sub_module_title"`
|
|
}
|
|
|
|
func (q *Queries) GetFullHierarchyByCourseID(ctx context.Context, id int64) ([]GetFullHierarchyByCourseIDRow, error) {
|
|
rows, err := q.db.Query(ctx, GetFullHierarchyByCourseID, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetFullHierarchyByCourseIDRow
|
|
for rows.Next() {
|
|
var i GetFullHierarchyByCourseIDRow
|
|
if err := rows.Scan(
|
|
&i.CourseID,
|
|
&i.CourseTitle,
|
|
&i.LevelID,
|
|
&i.CefrLevel,
|
|
&i.ModuleID,
|
|
&i.ModuleTitle,
|
|
&i.SubModuleID,
|
|
&i.SubModuleTitle,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetLevelsByCourseID = `-- name: GetLevelsByCourseID :many
|
|
SELECT id, course_id, cefr_level, display_order, is_active, created_at
|
|
FROM levels
|
|
WHERE course_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) GetLevelsByCourseID(ctx context.Context, courseID int64) ([]Level, error) {
|
|
rows, err := q.db.Query(ctx, GetLevelsByCourseID, courseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Level
|
|
for rows.Next() {
|
|
var i Level
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.CefrLevel,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetModulesByLevelID = `-- name: GetModulesByLevelID :many
|
|
SELECT id, level_id, title, description, display_order, is_active, created_at
|
|
FROM modules
|
|
WHERE level_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) GetModulesByLevelID(ctx context.Context, levelID int64) ([]Module, error) {
|
|
rows, err := q.db.Query(ctx, GetModulesByLevelID, levelID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Module
|
|
for rows.Next() {
|
|
var i Module
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetSubModuleLessons = `-- name: GetSubModuleLessons :many
|
|
SELECT
|
|
smp.id,
|
|
smp.sub_module_id,
|
|
smp.question_set_id,
|
|
smp.intro_video_url,
|
|
smp.display_order,
|
|
smp.is_active,
|
|
qs.title,
|
|
qs.description,
|
|
qs.status,
|
|
qs.set_type,
|
|
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
|
FROM sub_module_lessons smp
|
|
JOIN question_sets qs ON qs.id = smp.question_set_id
|
|
WHERE smp.sub_module_id = $1
|
|
AND smp.is_active = TRUE
|
|
AND qs.set_type = 'QUIZ'
|
|
ORDER BY smp.display_order ASC, smp.id ASC
|
|
`
|
|
|
|
type GetSubModuleLessonsRow struct {
|
|
ID int64 `json:"id"`
|
|
SubModuleID int64 `json:"sub_module_id"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
IntroVideoUrl pgtype.Text `json:"intro_video_url"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Status string `json:"status"`
|
|
SetType string `json:"set_type"`
|
|
QuestionCount int64 `json:"question_count"`
|
|
}
|
|
|
|
func (q *Queries) GetSubModuleLessons(ctx context.Context, subModuleID int64) ([]GetSubModuleLessonsRow, error) {
|
|
rows, err := q.db.Query(ctx, GetSubModuleLessons, subModuleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetSubModuleLessonsRow
|
|
for rows.Next() {
|
|
var i GetSubModuleLessonsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.QuestionSetID,
|
|
&i.IntroVideoUrl,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Status,
|
|
&i.SetType,
|
|
&i.QuestionCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetSubModulePractices = `-- name: GetSubModulePractices :many
|
|
SELECT
|
|
smp.id,
|
|
smp.sub_module_id,
|
|
smp.title,
|
|
smp.description,
|
|
smp.thumbnail,
|
|
smp.intro_video_url,
|
|
smp.question_set_id,
|
|
smp.display_order,
|
|
smp.is_active,
|
|
qs.status,
|
|
qs.set_type,
|
|
(SELECT COUNT(*) FROM question_set_items qsi WHERE qsi.set_id = qs.id) AS question_count
|
|
FROM sub_module_practices smp
|
|
JOIN question_sets qs ON qs.id = smp.question_set_id
|
|
WHERE smp.sub_module_id = $1
|
|
AND smp.is_active = TRUE
|
|
AND qs.set_type = 'PRACTICE'
|
|
ORDER BY smp.display_order ASC, smp.id ASC
|
|
`
|
|
|
|
type GetSubModulePracticesRow struct {
|
|
ID int64 `json:"id"`
|
|
SubModuleID int64 `json:"sub_module_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IntroVideoUrl pgtype.Text `json:"intro_video_url"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
SetType string `json:"set_type"`
|
|
QuestionCount int64 `json:"question_count"`
|
|
}
|
|
|
|
func (q *Queries) GetSubModulePractices(ctx context.Context, subModuleID int64) ([]GetSubModulePracticesRow, error) {
|
|
rows, err := q.db.Query(ctx, GetSubModulePractices, subModuleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetSubModulePracticesRow
|
|
for rows.Next() {
|
|
var i GetSubModulePracticesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.IntroVideoUrl,
|
|
&i.QuestionSetID,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.SetType,
|
|
&i.QuestionCount,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetSubModuleVideos = `-- name: GetSubModuleVideos :many
|
|
SELECT id, sub_module_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, display_order, status, vimeo_id, vimeo_embed_url, vimeo_player_html, vimeo_status, video_host_provider, created_at
|
|
FROM sub_module_videos
|
|
WHERE sub_module_id = $1
|
|
AND status != 'ARCHIVED'
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) GetSubModuleVideos(ctx context.Context, subModuleID int64) ([]SubModuleVideo, error) {
|
|
rows, err := q.db.Query(ctx, GetSubModuleVideos, subModuleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []SubModuleVideo
|
|
for rows.Next() {
|
|
var i SubModuleVideo
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SubModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.VideoUrl,
|
|
&i.Duration,
|
|
&i.Resolution,
|
|
&i.IsPublished,
|
|
&i.PublishDate,
|
|
&i.Visibility,
|
|
&i.InstructorID,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.Status,
|
|
&i.VimeoID,
|
|
&i.VimeoEmbedUrl,
|
|
&i.VimeoPlayerHtml,
|
|
&i.VimeoStatus,
|
|
&i.VideoHostProvider,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetSubModulesByModuleID = `-- name: GetSubModulesByModuleID :many
|
|
SELECT id, module_id, title, description, display_order, is_active, created_at, legacy_sub_course_id
|
|
FROM sub_modules
|
|
WHERE module_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) GetSubModulesByModuleID(ctx context.Context, moduleID int64) ([]SubModule, error) {
|
|
rows, err := q.db.Query(ctx, GetSubModulesByModuleID, moduleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []SubModule
|
|
for rows.Next() {
|
|
var i SubModule
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.LegacySubCourseID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|