Yimaru-BackEnd/gen/db/exam_prep_unit_modules.sql.go
Yared Yemane bc2357374b Add practice-existence flags and refresh API contracts.
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>
2026-05-08 11:57:11 -07:00

285 lines
7.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: exam_prep_unit_modules.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const ExamPrepCreateUnitModule = `-- 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
id, unit_id, name, description, thumbnail, icon, sort_order, created_at, updated_at
`
type ExamPrepCreateUnitModuleParams struct {
UnitID int64 `json:"unit_id"`
Name string `json:"name"`
Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"`
Icon pgtype.Text `json:"icon"`
}
func (q *Queries) ExamPrepCreateUnitModule(ctx context.Context, arg ExamPrepCreateUnitModuleParams) (ExamPrepUnitModule, error) {
row := q.db.QueryRow(ctx, ExamPrepCreateUnitModule,
arg.UnitID,
arg.Name,
arg.Description,
arg.Thumbnail,
arg.Icon,
)
var i ExamPrepUnitModule
err := row.Scan(
&i.ID,
&i.UnitID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.Icon,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const ExamPrepDeleteUnitModule = `-- name: ExamPrepDeleteUnitModule :exec
DELETE FROM exam_prep.unit_modules
WHERE id = $1
`
func (q *Queries) ExamPrepDeleteUnitModule(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, ExamPrepDeleteUnitModule, id)
return err
}
const ExamPrepGetUnitModuleByID = `-- name: ExamPrepGetUnitModuleByID :one
SELECT
m.id, m.unit_id, m.name, m.description, m.thumbnail, m.icon, m.sort_order, m.created_at, m.updated_at,
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
`
type ExamPrepGetUnitModuleByIDRow 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"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
HasPractice bool `json:"has_practice"`
}
func (q *Queries) ExamPrepGetUnitModuleByID(ctx context.Context, id int64) (ExamPrepGetUnitModuleByIDRow, error) {
row := q.db.QueryRow(ctx, ExamPrepGetUnitModuleByID, id)
var i ExamPrepGetUnitModuleByIDRow
err := row.Scan(
&i.ID,
&i.UnitID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.Icon,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
&i.HasPractice,
)
return i, err
}
const ExamPrepListUnitModuleIDsByUnit = `-- name: ExamPrepListUnitModuleIDsByUnit :many
SELECT
m.id
FROM exam_prep.unit_modules m
WHERE
m.unit_id = $1
ORDER BY
m.id
`
func (q *Queries) ExamPrepListUnitModuleIDsByUnit(ctx context.Context, unitID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, ExamPrepListUnitModuleIDsByUnit, unitID)
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 ExamPrepListUnitModulesByUnit = `-- 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
`
type ExamPrepListUnitModulesByUnitParams struct {
UnitID int64 `json:"unit_id"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
type ExamPrepListUnitModulesByUnitRow struct {
TotalCount int64 `json:"total_count"`
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"`
LessonsCount int64 `json:"lessons_count"`
PracticesCount int64 `json:"practices_count"`
HasPractice bool `json:"has_practice"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) ExamPrepListUnitModulesByUnit(ctx context.Context, arg ExamPrepListUnitModulesByUnitParams) ([]ExamPrepListUnitModulesByUnitRow, error) {
rows, err := q.db.Query(ctx, ExamPrepListUnitModulesByUnit, arg.UnitID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ExamPrepListUnitModulesByUnitRow
for rows.Next() {
var i ExamPrepListUnitModulesByUnitRow
if err := rows.Scan(
&i.TotalCount,
&i.ID,
&i.UnitID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.Icon,
&i.SortOrder,
&i.LessonsCount,
&i.PracticesCount,
&i.HasPractice,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const ExamPrepUpdateUnitModule = `-- name: ExamPrepUpdateUnitModule :one
UPDATE exam_prep.unit_modules
SET
name = coalesce($1::varchar, name),
description = coalesce($2::text, description),
thumbnail = coalesce($3::text, thumbnail),
icon = coalesce($4::text, icon),
sort_order = coalesce($5::int, sort_order),
updated_at = CURRENT_TIMESTAMP
WHERE id = $6
RETURNING
id, unit_id, name, description, thumbnail, icon, sort_order, created_at, updated_at
`
type ExamPrepUpdateUnitModuleParams struct {
Name pgtype.Text `json:"name"`
Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"`
Icon pgtype.Text `json:"icon"`
SortOrder pgtype.Int4 `json:"sort_order"`
ID int64 `json:"id"`
}
func (q *Queries) ExamPrepUpdateUnitModule(ctx context.Context, arg ExamPrepUpdateUnitModuleParams) (ExamPrepUnitModule, error) {
row := q.db.QueryRow(ctx, ExamPrepUpdateUnitModule,
arg.Name,
arg.Description,
arg.Thumbnail,
arg.Icon,
arg.SortOrder,
arg.ID,
)
var i ExamPrepUnitModule
err := row.Scan(
&i.ID,
&i.UnitID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.Icon,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}