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>
281 lines
6.3 KiB
Go
281 lines
6.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: lms_modules.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateModule = `-- name: CreateModule :one
|
|
INSERT INTO modules (program_id, course_id, name, description, icon, sort_order)
|
|
SELECT
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
coalesce((
|
|
SELECT
|
|
max(m.sort_order)
|
|
FROM modules m
|
|
WHERE
|
|
m.course_id = $2), 0) + 1
|
|
RETURNING
|
|
id, program_id, course_id, name, description, icon, created_at, updated_at, sort_order
|
|
`
|
|
|
|
type CreateModuleParams struct {
|
|
ProgramID int64 `json:"program_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
}
|
|
|
|
func (q *Queries) CreateModule(ctx context.Context, arg CreateModuleParams) (Module, error) {
|
|
row := q.db.QueryRow(ctx, CreateModule,
|
|
arg.ProgramID,
|
|
arg.CourseID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Icon,
|
|
)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.CourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteModule = `-- name: DeleteModule :exec
|
|
DELETE FROM modules
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteModule(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteModule, id)
|
|
return err
|
|
}
|
|
|
|
const GetModuleByID = `-- name: GetModuleByID :one
|
|
SELECT
|
|
m.id, m.program_id, m.course_id, m.name, m.description, m.icon, m.created_at, m.updated_at, m.sort_order,
|
|
EXISTS (
|
|
SELECT 1
|
|
FROM lms_practices p
|
|
WHERE p.module_id = m.id
|
|
AND p.lesson_id IS NULL
|
|
) AS has_practice
|
|
FROM modules
|
|
m
|
|
WHERE m.id = $1
|
|
`
|
|
|
|
type GetModuleByIDRow struct {
|
|
ID int64 `json:"id"`
|
|
ProgramID int64 `json:"program_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
HasPractice bool `json:"has_practice"`
|
|
}
|
|
|
|
func (q *Queries) GetModuleByID(ctx context.Context, id int64) (GetModuleByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, GetModuleByID, id)
|
|
var i GetModuleByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.CourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
&i.HasPractice,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListModuleIDsByCourse = `-- name: ListModuleIDsByCourse :many
|
|
SELECT
|
|
m.id
|
|
FROM
|
|
modules AS m
|
|
WHERE
|
|
m.course_id = $1
|
|
ORDER BY
|
|
m.id
|
|
`
|
|
|
|
func (q *Queries) ListModuleIDsByCourse(ctx context.Context, courseID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListModuleIDsByCourse, courseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var id int64
|
|
if err := rows.Scan(&id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListModulesByProgramAndCourse = `-- name: ListModulesByProgramAndCourse :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
m.id,
|
|
m.program_id,
|
|
m.course_id,
|
|
m.name,
|
|
m.description,
|
|
m.icon,
|
|
m.sort_order,
|
|
m.created_at,
|
|
m.updated_at,
|
|
EXISTS (
|
|
SELECT 1
|
|
FROM lms_practices p
|
|
WHERE p.module_id = m.id
|
|
AND p.lesson_id IS NULL
|
|
) AS has_practice
|
|
FROM
|
|
modules m
|
|
WHERE
|
|
m.program_id = $1
|
|
AND m.course_id = $2
|
|
ORDER BY
|
|
m.sort_order ASC,
|
|
m.id ASC
|
|
LIMIT $3
|
|
OFFSET $4
|
|
`
|
|
|
|
type ListModulesByProgramAndCourseParams struct {
|
|
ProgramID int64 `json:"program_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListModulesByProgramAndCourseRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
ProgramID int64 `json:"program_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
HasPractice bool `json:"has_practice"`
|
|
}
|
|
|
|
func (q *Queries) ListModulesByProgramAndCourse(ctx context.Context, arg ListModulesByProgramAndCourseParams) ([]ListModulesByProgramAndCourseRow, error) {
|
|
rows, err := q.db.Query(ctx, ListModulesByProgramAndCourse,
|
|
arg.ProgramID,
|
|
arg.CourseID,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListModulesByProgramAndCourseRow
|
|
for rows.Next() {
|
|
var i ListModulesByProgramAndCourseRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.CourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.HasPractice,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateModule = `-- name: UpdateModule :one
|
|
UPDATE modules
|
|
SET
|
|
name = COALESCE($1::varchar, name),
|
|
description = COALESCE($2::text, description),
|
|
icon = COALESCE($3::text, icon),
|
|
sort_order = coalesce($4::int, sort_order),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
id = $5
|
|
RETURNING
|
|
id, program_id, course_id, name, description, icon, created_at, updated_at, sort_order
|
|
`
|
|
|
|
type UpdateModuleParams struct {
|
|
Name pgtype.Text `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
SortOrder pgtype.Int4 `json:"sort_order"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateModule(ctx context.Context, arg UpdateModuleParams) (Module, error) {
|
|
row := q.db.QueryRow(ctx, UpdateModule,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Icon,
|
|
arg.SortOrder,
|
|
arg.ID,
|
|
)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.CourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|