added method GetQuestionListByQuizID
This commit is contained in:
parent
809c5e9c74
commit
1d0b0c8b4c
@ -1676,3 +1676,6 @@ WHERE a.result = true AND s.id IS NULL AND a.deleted = false
|
||||
AND r.deleted = false AND q.deleted = false
|
||||
AND u.deleted = false AND t.active = true
|
||||
AND t.expiration = false;
|
||||
|
||||
-- name: GetQuestionListByQuizID :many
|
||||
SELECT * from question where quiz_id=$1 and deleted = false;
|
||||
|
||||
@ -3367,6 +3367,49 @@ func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getQuestionListByQuizID = `-- name: GetQuestionListByQuizID :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session, auditory from question where quiz_id=$1 and deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetQuestionListByQuizID(ctx context.Context, quizID int64) ([]Question, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getQuestionListByQuizID, quizID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Question
|
||||
for rows.Next() {
|
||||
var i Question
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.QuizID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Questiontype,
|
||||
&i.Required,
|
||||
&i.Deleted,
|
||||
&i.Page,
|
||||
&i.Content,
|
||||
&i.Version,
|
||||
pq.Array(&i.ParentIds),
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getQuestionTitle = `-- name: GetQuestionTitle :one
|
||||
SELECT title, questiontype,page FROM question WHERE id = $1
|
||||
`
|
||||
|
||||
@ -5,13 +5,14 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"github.com/lib/pq"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
@ -559,3 +560,31 @@ func (r *QuestionRepository) CheckQuestionOwner(ctx context.Context, accountID s
|
||||
}
|
||||
return accountID == id, nil
|
||||
}
|
||||
|
||||
func (r *QuestionRepository) GetQuestionListByQuizID(ctx context.Context, quizID int64) ([]model.Question, error) {
|
||||
rows, err := r.queries.GetQuestionListByQuizID(ctx, quizID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var questions []model.Question
|
||||
for _, row := range rows {
|
||||
questions = append(questions, model.Question{
|
||||
Id: uint64(row.ID),
|
||||
QuizId: uint64(row.QuizID),
|
||||
Title: row.Title,
|
||||
Description: row.Description.String,
|
||||
Type: string(row.Questiontype.([]byte)),
|
||||
Required: row.Required.Bool,
|
||||
Deleted: row.Deleted.Bool,
|
||||
Page: int(row.Page.Int16),
|
||||
Content: row.Content.String,
|
||||
Version: int(row.Version.Int16),
|
||||
ParentIds: row.ParentIds,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Auditory: row.Auditory,
|
||||
Session: row.Session,
|
||||
})
|
||||
}
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user