RezinaLMS-BackEnd/gen/db/practice_progress.sql.go
Yared Yemane fb528e9e77 Scope practice completion to the specific parent link in Learn English and Exam Prep.
Add migration 000109, require parent context on complete, and update progress queries and LMS rollups.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-22 15:37:20 +03:00

138 lines
3.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: practice_progress.sql
package dbgen
import (
"context"
)
const GetFirstIncompletePreviousPractice = `-- name: GetFirstIncompletePreviousPractice :one
WITH target AS (
SELECT id, owner_type, owner_id, COALESCE(display_order, 0) AS display_order
FROM question_sets
WHERE id = $2::BIGINT
AND set_type = 'PRACTICE'
AND status = 'PUBLISHED'
),
candidates AS (
SELECT qs.id, qs.title, COALESCE(qs.display_order, 0) AS display_order
FROM question_sets qs
JOIN target t
ON qs.owner_type = t.owner_type
AND qs.owner_id = t.owner_id
WHERE qs.set_type = 'PRACTICE'
AND qs.status = 'PUBLISHED'
AND COALESCE(qs.display_order, 0) < t.display_order
)
SELECT c.id, c.title, c.display_order
FROM candidates c
LEFT JOIN user_practice_progress upp
ON upp.question_set_id = c.id
AND upp.user_id = $1::BIGINT
AND upp.completed_at IS NOT NULL
WHERE upp.id IS NULL
ORDER BY c.display_order ASC, c.id ASC
LIMIT 1
`
type GetFirstIncompletePreviousPracticeParams struct {
UserID int64 `json:"user_id"`
QuestionSetID int64 `json:"question_set_id"`
}
type GetFirstIncompletePreviousPracticeRow struct {
ID int64 `json:"id"`
Title string `json:"title"`
DisplayOrder int32 `json:"display_order"`
}
func (q *Queries) GetFirstIncompletePreviousPractice(ctx context.Context, arg GetFirstIncompletePreviousPracticeParams) (GetFirstIncompletePreviousPracticeRow, error) {
row := q.db.QueryRow(ctx, GetFirstIncompletePreviousPractice, arg.UserID, arg.QuestionSetID)
var i GetFirstIncompletePreviousPracticeRow
err := row.Scan(&i.ID, &i.Title, &i.DisplayOrder)
return i, err
}
const HasUserCompletedPracticeAtParent = `-- name: HasUserCompletedPracticeAtParent :one
SELECT EXISTS (
SELECT 1
FROM user_practice_progress
WHERE user_id = $1::BIGINT
AND question_set_id = $2::BIGINT
AND content_domain = $3::VARCHAR
AND parent_kind = $4::VARCHAR
AND parent_id = $5::BIGINT
AND completed_at IS NOT NULL
)::boolean AS completed
`
type HasUserCompletedPracticeAtParentParams struct {
UserID int64 `json:"user_id"`
QuestionSetID int64 `json:"question_set_id"`
ContentDomain string `json:"content_domain"`
ParentKind string `json:"parent_kind"`
ParentID int64 `json:"parent_id"`
}
func (q *Queries) HasUserCompletedPracticeAtParent(ctx context.Context, arg HasUserCompletedPracticeAtParentParams) (bool, error) {
row := q.db.QueryRow(ctx, HasUserCompletedPracticeAtParent,
arg.UserID,
arg.QuestionSetID,
arg.ContentDomain,
arg.ParentKind,
arg.ParentID,
)
var completed bool
err := row.Scan(&completed)
return completed, err
}
const MarkPracticeCompleted = `-- name: MarkPracticeCompleted :execrows
INSERT INTO user_practice_progress (
user_id,
question_set_id,
content_domain,
parent_kind,
parent_id,
completed_at,
updated_at
)
VALUES (
$1::BIGINT,
$2::BIGINT,
$3::VARCHAR,
$4::VARCHAR,
$5::BIGINT,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
)
ON CONFLICT (user_id, question_set_id, content_domain, parent_kind, parent_id) DO UPDATE
SET completed_at = EXCLUDED.completed_at,
updated_at = EXCLUDED.updated_at
`
type MarkPracticeCompletedParams struct {
UserID int64 `json:"user_id"`
QuestionSetID int64 `json:"question_set_id"`
ContentDomain string `json:"content_domain"`
ParentKind string `json:"parent_kind"`
ParentID int64 `json:"parent_id"`
}
func (q *Queries) MarkPracticeCompleted(ctx context.Context, arg MarkPracticeCompletedParams) (int64, error) {
result, err := q.db.Exec(ctx, MarkPracticeCompleted,
arg.UserID,
arg.QuestionSetID,
arg.ContentDomain,
arg.ParentKind,
arg.ParentID,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}