103 lines
2.8 KiB
Go
103 lines
2.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: user_practice_progress.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const GetFirstIncompletePreviousPractice = `-- name: GetFirstIncompletePreviousPractice :one
|
|
SELECT
|
|
p.id,
|
|
p.title,
|
|
p.display_order
|
|
FROM question_sets target
|
|
JOIN question_sets p
|
|
ON p.owner_type = 'SUB_COURSE'
|
|
AND p.owner_id = target.owner_id
|
|
AND p.set_type = 'PRACTICE'
|
|
AND p.status = 'PUBLISHED'
|
|
AND (
|
|
p.display_order < target.display_order OR
|
|
(p.display_order = target.display_order AND p.id < target.id)
|
|
)
|
|
LEFT JOIN user_practice_progress upp
|
|
ON upp.question_set_id = p.id
|
|
AND upp.user_id = $1::BIGINT
|
|
AND upp.completed_at IS NOT NULL
|
|
WHERE target.id = $2::BIGINT
|
|
AND target.set_type = 'PRACTICE'
|
|
AND target.owner_type = 'SUB_COURSE'
|
|
AND target.status = 'PUBLISHED'
|
|
AND upp.question_set_id IS NULL
|
|
ORDER BY p.display_order ASC, p.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 MarkPracticeCompleted = `-- name: MarkPracticeCompleted :one
|
|
INSERT INTO user_practice_progress (
|
|
user_id,
|
|
sub_course_id,
|
|
question_set_id,
|
|
completed_at,
|
|
updated_at
|
|
)
|
|
SELECT
|
|
$1::BIGINT,
|
|
qs.owner_id::BIGINT,
|
|
qs.id,
|
|
CURRENT_TIMESTAMP,
|
|
CURRENT_TIMESTAMP
|
|
FROM question_sets qs
|
|
WHERE qs.id = $2::BIGINT
|
|
AND qs.set_type = 'PRACTICE'
|
|
AND qs.owner_type = 'SUB_COURSE'
|
|
AND qs.status = 'PUBLISHED'
|
|
ON CONFLICT (user_id, question_set_id)
|
|
DO UPDATE SET
|
|
completed_at = CURRENT_TIMESTAMP,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
RETURNING id, user_id, sub_course_id, question_set_id, completed_at, created_at, updated_at
|
|
`
|
|
|
|
type MarkPracticeCompletedParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
QuestionSetID int64 `json:"question_set_id"`
|
|
}
|
|
|
|
func (q *Queries) MarkPracticeCompleted(ctx context.Context, arg MarkPracticeCompletedParams) (UserPracticeProgress, error) {
|
|
row := q.db.QueryRow(ctx, MarkPracticeCompleted, arg.UserID, arg.QuestionSetID)
|
|
var i UserPracticeProgress
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.SubCourseID,
|
|
&i.QuestionSetID,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|