757 lines
19 KiB
Go
757 lines
19 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: initial_assessment.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const AddAttemptQuestion = `-- name: AddAttemptQuestion :exec
|
|
INSERT INTO assessment_attempt_questions (
|
|
attempt_id,
|
|
question_id,
|
|
question_type,
|
|
points
|
|
)
|
|
VALUES (
|
|
$1, -- attempt_id
|
|
$2, -- question_id
|
|
$3, -- question_type
|
|
$4 -- points
|
|
)
|
|
`
|
|
|
|
type AddAttemptQuestionParams struct {
|
|
AttemptID int64 `json:"attempt_id"`
|
|
QuestionID int64 `json:"question_id"`
|
|
QuestionType string `json:"question_type"`
|
|
Points int32 `json:"points"`
|
|
}
|
|
|
|
func (q *Queries) AddAttemptQuestion(ctx context.Context, arg AddAttemptQuestionParams) error {
|
|
_, err := q.db.Exec(ctx, AddAttemptQuestion,
|
|
arg.AttemptID,
|
|
arg.QuestionID,
|
|
arg.QuestionType,
|
|
arg.Points,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const CreateAssessmentAttempt = `-- name: CreateAssessmentAttempt :one
|
|
|
|
INSERT INTO assessment_attempts (
|
|
user_id,
|
|
total_questions,
|
|
total_points,
|
|
status
|
|
)
|
|
VALUES (
|
|
$1, -- user_id
|
|
$2, -- total_questions
|
|
$3, -- total_points
|
|
'IN_PROGRESS'
|
|
)
|
|
RETURNING id, user_id, total_questions, total_points, score, percentage, status, started_at, submitted_at, evaluated_at, created_at, updated_at
|
|
`
|
|
|
|
type CreateAssessmentAttemptParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
TotalQuestions int32 `json:"total_questions"`
|
|
TotalPoints int32 `json:"total_points"`
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
func (q *Queries) CreateAssessmentAttempt(ctx context.Context, arg CreateAssessmentAttemptParams) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, CreateAssessmentAttempt, arg.UserID, arg.TotalQuestions, arg.TotalPoints)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.TotalQuestions,
|
|
&i.TotalPoints,
|
|
&i.Score,
|
|
&i.Percentage,
|
|
&i.Status,
|
|
&i.StartedAt,
|
|
&i.SubmittedAt,
|
|
&i.EvaluatedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateAssessmentQuestion = `-- name: CreateAssessmentQuestion :one
|
|
INSERT INTO assessment_questions (
|
|
title,
|
|
description,
|
|
question_type,
|
|
difficulty_level,
|
|
points,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, -- title
|
|
$2, -- description
|
|
$3, -- question_type
|
|
$4, -- difficulty_level
|
|
$5, -- points
|
|
$6 -- is_active
|
|
)
|
|
RETURNING id, title, description, question_type, difficulty_level, points, is_active, created_at, updated_at
|
|
`
|
|
|
|
type CreateAssessmentQuestionParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
QuestionType string `json:"question_type"`
|
|
DifficultyLevel pgtype.Text `json:"difficulty_level"`
|
|
Points int32 `json:"points"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) CreateAssessmentQuestion(ctx context.Context, arg CreateAssessmentQuestionParams) (AssessmentQuestion, error) {
|
|
row := q.db.QueryRow(ctx, CreateAssessmentQuestion,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.QuestionType,
|
|
arg.DifficultyLevel,
|
|
arg.Points,
|
|
arg.IsActive,
|
|
)
|
|
var i AssessmentQuestion
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.QuestionType,
|
|
&i.DifficultyLevel,
|
|
&i.Points,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateQuestionOption = `-- name: CreateQuestionOption :one
|
|
INSERT INTO assessment_question_options (
|
|
question_id,
|
|
option_text,
|
|
option_order,
|
|
is_correct
|
|
)
|
|
VALUES (
|
|
$1, -- question_id
|
|
$2, -- option_text
|
|
$3, -- option_order
|
|
$4 -- is_correct
|
|
)
|
|
RETURNING id, question_id, option_text, option_order, is_correct, created_at
|
|
`
|
|
|
|
type CreateQuestionOptionParams struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
OptionText string `json:"option_text"`
|
|
OptionOrder int32 `json:"option_order"`
|
|
IsCorrect bool `json:"is_correct"`
|
|
}
|
|
|
|
func (q *Queries) CreateQuestionOption(ctx context.Context, arg CreateQuestionOptionParams) (AssessmentQuestionOption, error) {
|
|
row := q.db.QueryRow(ctx, CreateQuestionOption,
|
|
arg.QuestionID,
|
|
arg.OptionText,
|
|
arg.OptionOrder,
|
|
arg.IsCorrect,
|
|
)
|
|
var i AssessmentQuestionOption
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.OptionText,
|
|
&i.OptionOrder,
|
|
&i.IsCorrect,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateShortAnswer = `-- name: CreateShortAnswer :one
|
|
INSERT INTO assessment_short_answers (
|
|
question_id,
|
|
correct_answer
|
|
)
|
|
VALUES (
|
|
$1, -- question_id
|
|
$2 -- correct_answer
|
|
)
|
|
RETURNING id, question_id, correct_answer, created_at
|
|
`
|
|
|
|
type CreateShortAnswerParams struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
CorrectAnswer string `json:"correct_answer"`
|
|
}
|
|
|
|
func (q *Queries) CreateShortAnswer(ctx context.Context, arg CreateShortAnswerParams) (AssessmentShortAnswer, error) {
|
|
row := q.db.QueryRow(ctx, CreateShortAnswer, arg.QuestionID, arg.CorrectAnswer)
|
|
var i AssessmentShortAnswer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.CorrectAnswer,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteAssessmentQuestion = `-- name: DeleteAssessmentQuestion :exec
|
|
DELETE FROM assessment_questions
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteAssessmentQuestion(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteAssessmentQuestion, id)
|
|
return err
|
|
}
|
|
|
|
const DeleteQuestionOptionsByQuestionID = `-- name: DeleteQuestionOptionsByQuestionID :exec
|
|
DELETE FROM assessment_question_options
|
|
WHERE question_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteQuestionOptionsByQuestionID(ctx context.Context, questionID int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteQuestionOptionsByQuestionID, questionID)
|
|
return err
|
|
}
|
|
|
|
const EvaluateMCQAnswer = `-- name: EvaluateMCQAnswer :exec
|
|
UPDATE assessment_attempt_answers a
|
|
SET
|
|
is_correct = o.is_correct,
|
|
awarded_points = CASE WHEN o.is_correct THEN q.points ELSE 0 END
|
|
FROM assessment_question_options o
|
|
JOIN assessment_questions q ON q.id = a.question_id
|
|
WHERE a.selected_option_id = o.id
|
|
AND a.attempt_id = $1
|
|
`
|
|
|
|
func (q *Queries) EvaluateMCQAnswer(ctx context.Context, attemptID int64) error {
|
|
_, err := q.db.Exec(ctx, EvaluateMCQAnswer, attemptID)
|
|
return err
|
|
}
|
|
|
|
const EvaluateShortAnswer = `-- name: EvaluateShortAnswer :exec
|
|
UPDATE assessment_attempt_answers a
|
|
SET
|
|
is_correct = EXISTS (
|
|
SELECT 1
|
|
FROM assessment_short_answers s
|
|
WHERE s.question_id = a.question_id
|
|
AND LOWER(TRIM(s.correct_answer)) = LOWER(TRIM(a.submitted_text))
|
|
),
|
|
awarded_points = CASE
|
|
WHEN EXISTS (
|
|
SELECT 1
|
|
FROM assessment_short_answers s
|
|
WHERE s.question_id = a.question_id
|
|
AND LOWER(TRIM(s.correct_answer)) = LOWER(TRIM(a.submitted_text))
|
|
)
|
|
THEN q.points
|
|
ELSE 0
|
|
END
|
|
FROM assessment_questions q
|
|
WHERE a.question_id = q.id
|
|
AND a.attempt_id = $1
|
|
`
|
|
|
|
func (q *Queries) EvaluateShortAnswer(ctx context.Context, attemptID int64) error {
|
|
_, err := q.db.Exec(ctx, EvaluateShortAnswer, attemptID)
|
|
return err
|
|
}
|
|
|
|
const FinalizeAssessmentAttempt = `-- name: FinalizeAssessmentAttempt :exec
|
|
UPDATE assessment_attempts
|
|
SET
|
|
score = sub.total_score,
|
|
percentage = ROUND((sub.total_score::NUMERIC / total_points) * 100, 2),
|
|
status = 'EVALUATED',
|
|
evaluated_at = CURRENT_TIMESTAMP,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
FROM (
|
|
SELECT attempt_id, SUM(awarded_points) AS total_score
|
|
FROM assessment_attempt_answers
|
|
WHERE attempt_id = $1
|
|
GROUP BY attempt_id
|
|
) sub
|
|
WHERE assessment_attempts.id = sub.attempt_id
|
|
`
|
|
|
|
func (q *Queries) FinalizeAssessmentAttempt(ctx context.Context, attemptID int64) error {
|
|
_, err := q.db.Exec(ctx, FinalizeAssessmentAttempt, attemptID)
|
|
return err
|
|
}
|
|
|
|
const GetActiveAssessmentQuestions = `-- name: GetActiveAssessmentQuestions :many
|
|
SELECT id, title, description, question_type, difficulty_level, points, is_active, created_at, updated_at
|
|
FROM assessment_questions
|
|
WHERE is_active = true
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetActiveAssessmentQuestions(ctx context.Context) ([]AssessmentQuestion, error) {
|
|
rows, err := q.db.Query(ctx, GetActiveAssessmentQuestions)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AssessmentQuestion
|
|
for rows.Next() {
|
|
var i AssessmentQuestion
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.QuestionType,
|
|
&i.DifficultyLevel,
|
|
&i.Points,
|
|
&i.IsActive,
|
|
&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 GetAssessmentAttemptByID = `-- name: GetAssessmentAttemptByID :one
|
|
SELECT id, user_id, total_questions, total_points, score, percentage, status, started_at, submitted_at, evaluated_at, created_at, updated_at
|
|
FROM assessment_attempts
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetAssessmentAttemptByID(ctx context.Context, id int64) (AssessmentAttempt, error) {
|
|
row := q.db.QueryRow(ctx, GetAssessmentAttemptByID, id)
|
|
var i AssessmentAttempt
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.TotalQuestions,
|
|
&i.TotalPoints,
|
|
&i.Score,
|
|
&i.Percentage,
|
|
&i.Status,
|
|
&i.StartedAt,
|
|
&i.SubmittedAt,
|
|
&i.EvaluatedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetAssessmentQuestionByID = `-- name: GetAssessmentQuestionByID :one
|
|
SELECT id, title, description, question_type, difficulty_level, points, is_active, created_at, updated_at
|
|
FROM assessment_questions
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetAssessmentQuestionByID(ctx context.Context, id int64) (AssessmentQuestion, error) {
|
|
row := q.db.QueryRow(ctx, GetAssessmentQuestionByID, id)
|
|
var i AssessmentQuestion
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.QuestionType,
|
|
&i.DifficultyLevel,
|
|
&i.Points,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetAssessmentQuestionsPaginated = `-- name: GetAssessmentQuestionsPaginated :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
id,
|
|
title,
|
|
description,
|
|
question_type,
|
|
difficulty_level,
|
|
points,
|
|
is_active,
|
|
created_at,
|
|
updated_at
|
|
FROM assessment_questions
|
|
WHERE ($1 IS NULL OR question_type = $1)
|
|
AND ($2 IS NULL OR difficulty_level = $2)
|
|
AND ($3 IS NULL OR is_active = $3)
|
|
LIMIT $4
|
|
OFFSET $5
|
|
`
|
|
|
|
type GetAssessmentQuestionsPaginatedParams struct {
|
|
Column1 interface{} `json:"column_1"`
|
|
Column2 interface{} `json:"column_2"`
|
|
Column3 interface{} `json:"column_3"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type GetAssessmentQuestionsPaginatedRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
QuestionType string `json:"question_type"`
|
|
DifficultyLevel pgtype.Text `json:"difficulty_level"`
|
|
Points int32 `json:"points"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetAssessmentQuestionsPaginated(ctx context.Context, arg GetAssessmentQuestionsPaginatedParams) ([]GetAssessmentQuestionsPaginatedRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAssessmentQuestionsPaginated,
|
|
arg.Column1,
|
|
arg.Column2,
|
|
arg.Column3,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAssessmentQuestionsPaginatedRow
|
|
for rows.Next() {
|
|
var i GetAssessmentQuestionsPaginatedRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.QuestionType,
|
|
&i.DifficultyLevel,
|
|
&i.Points,
|
|
&i.IsActive,
|
|
&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 GetAttemptAnswers = `-- name: GetAttemptAnswers :many
|
|
SELECT id, attempt_id, question_id, selected_option_id, submitted_text, is_correct, awarded_points, created_at
|
|
FROM assessment_attempt_answers
|
|
WHERE attempt_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetAttemptAnswers(ctx context.Context, attemptID int64) ([]AssessmentAttemptAnswer, error) {
|
|
rows, err := q.db.Query(ctx, GetAttemptAnswers, attemptID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AssessmentAttemptAnswer
|
|
for rows.Next() {
|
|
var i AssessmentAttemptAnswer
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.AttemptID,
|
|
&i.QuestionID,
|
|
&i.SelectedOptionID,
|
|
&i.SubmittedText,
|
|
&i.IsCorrect,
|
|
&i.AwardedPoints,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetAttemptQuestions = `-- name: GetAttemptQuestions :many
|
|
SELECT
|
|
aq.question_id,
|
|
aq.question_type,
|
|
aq.points,
|
|
q.title,
|
|
q.description
|
|
FROM assessment_attempt_questions aq
|
|
JOIN assessment_questions q ON q.id = aq.question_id
|
|
WHERE aq.attempt_id = $1
|
|
`
|
|
|
|
type GetAttemptQuestionsRow struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
QuestionType string `json:"question_type"`
|
|
Points int32 `json:"points"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
}
|
|
|
|
func (q *Queries) GetAttemptQuestions(ctx context.Context, attemptID int64) ([]GetAttemptQuestionsRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAttemptQuestions, attemptID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAttemptQuestionsRow
|
|
for rows.Next() {
|
|
var i GetAttemptQuestionsRow
|
|
if err := rows.Scan(
|
|
&i.QuestionID,
|
|
&i.QuestionType,
|
|
&i.Points,
|
|
&i.Title,
|
|
&i.Description,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetQuestionOptions = `-- name: GetQuestionOptions :many
|
|
SELECT id, question_id, option_text, option_order, is_correct, created_at
|
|
FROM assessment_question_options
|
|
WHERE question_id = $1
|
|
ORDER BY option_order
|
|
`
|
|
|
|
func (q *Queries) GetQuestionOptions(ctx context.Context, questionID int64) ([]AssessmentQuestionOption, error) {
|
|
rows, err := q.db.Query(ctx, GetQuestionOptions, questionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AssessmentQuestionOption
|
|
for rows.Next() {
|
|
var i AssessmentQuestionOption
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.OptionText,
|
|
&i.OptionOrder,
|
|
&i.IsCorrect,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetShortAnswersByQuestionID = `-- name: GetShortAnswersByQuestionID :many
|
|
SELECT id, question_id, correct_answer, created_at
|
|
FROM assessment_short_answers
|
|
WHERE question_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetShortAnswersByQuestionID(ctx context.Context, questionID int64) ([]AssessmentShortAnswer, error) {
|
|
rows, err := q.db.Query(ctx, GetShortAnswersByQuestionID, questionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AssessmentShortAnswer
|
|
for rows.Next() {
|
|
var i AssessmentShortAnswer
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.CorrectAnswer,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetUserAssessmentAttempts = `-- name: GetUserAssessmentAttempts :many
|
|
SELECT
|
|
id,
|
|
user_id,
|
|
total_questions,
|
|
total_points,
|
|
score,
|
|
percentage,
|
|
status,
|
|
started_at,
|
|
submitted_at,
|
|
evaluated_at
|
|
FROM assessment_attempts
|
|
WHERE user_id = $1
|
|
ORDER BY started_at DESC
|
|
`
|
|
|
|
type GetUserAssessmentAttemptsRow struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
TotalQuestions int32 `json:"total_questions"`
|
|
TotalPoints int32 `json:"total_points"`
|
|
Score pgtype.Int4 `json:"score"`
|
|
Percentage pgtype.Numeric `json:"percentage"`
|
|
Status string `json:"status"`
|
|
StartedAt pgtype.Timestamptz `json:"started_at"`
|
|
SubmittedAt pgtype.Timestamptz `json:"submitted_at"`
|
|
EvaluatedAt pgtype.Timestamptz `json:"evaluated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserAssessmentAttempts(ctx context.Context, userID int64) ([]GetUserAssessmentAttemptsRow, error) {
|
|
rows, err := q.db.Query(ctx, GetUserAssessmentAttempts, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetUserAssessmentAttemptsRow
|
|
for rows.Next() {
|
|
var i GetUserAssessmentAttemptsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.TotalQuestions,
|
|
&i.TotalPoints,
|
|
&i.Score,
|
|
&i.Percentage,
|
|
&i.Status,
|
|
&i.StartedAt,
|
|
&i.SubmittedAt,
|
|
&i.EvaluatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const SubmitAssessmentAttempt = `-- name: SubmitAssessmentAttempt :exec
|
|
UPDATE assessment_attempts
|
|
SET
|
|
status = 'SUBMITTED',
|
|
submitted_at = CURRENT_TIMESTAMP,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) SubmitAssessmentAttempt(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, SubmitAssessmentAttempt, id)
|
|
return err
|
|
}
|
|
|
|
const UpdateAssessmentQuestion = `-- name: UpdateAssessmentQuestion :exec
|
|
UPDATE assessment_questions
|
|
SET
|
|
title = COALESCE($1, title),
|
|
description = COALESCE($2, description),
|
|
question_type = COALESCE($3, question_type),
|
|
difficulty_level = COALESCE($4, difficulty_level),
|
|
points = COALESCE($5, points),
|
|
is_active = COALESCE($6, is_active),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $7
|
|
`
|
|
|
|
type UpdateAssessmentQuestionParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
QuestionType string `json:"question_type"`
|
|
DifficultyLevel pgtype.Text `json:"difficulty_level"`
|
|
Points int32 `json:"points"`
|
|
IsActive bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateAssessmentQuestion(ctx context.Context, arg UpdateAssessmentQuestionParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateAssessmentQuestion,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.QuestionType,
|
|
arg.DifficultyLevel,
|
|
arg.Points,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpsertAttemptAnswer = `-- name: UpsertAttemptAnswer :exec
|
|
INSERT INTO assessment_attempt_answers (
|
|
attempt_id,
|
|
question_id,
|
|
selected_option_id,
|
|
submitted_text
|
|
)
|
|
VALUES (
|
|
$1, -- attempt_id
|
|
$2, -- question_id
|
|
$3, -- selected_option_id
|
|
$4 -- submitted_text
|
|
)
|
|
ON CONFLICT (attempt_id, question_id)
|
|
DO UPDATE SET
|
|
selected_option_id = EXCLUDED.selected_option_id,
|
|
submitted_text = EXCLUDED.submitted_text
|
|
`
|
|
|
|
type UpsertAttemptAnswerParams struct {
|
|
AttemptID int64 `json:"attempt_id"`
|
|
QuestionID int64 `json:"question_id"`
|
|
SelectedOptionID pgtype.Int8 `json:"selected_option_id"`
|
|
SubmittedText pgtype.Text `json:"submitted_text"`
|
|
}
|
|
|
|
func (q *Queries) UpsertAttemptAnswer(ctx context.Context, arg UpsertAttemptAnswerParams) error {
|
|
_, err := q.db.Exec(ctx, UpsertAttemptAnswer,
|
|
arg.AttemptID,
|
|
arg.QuestionID,
|
|
arg.SelectedOptionID,
|
|
arg.SubmittedText,
|
|
)
|
|
return err
|
|
}
|