Merge branch 'rpcquery' into 'main'
Rpcquery See merge request backend/quiz/common!12
This commit is contained in:
commit
60b55541d6
@ -648,3 +648,11 @@ SELECT
|
||||
(SELECT registration_count FROM Registrations) AS registrations,
|
||||
(SELECT quiz_count FROM Quizes) AS quizes,
|
||||
(SELECT result_count FROM Results) AS results;
|
||||
|
||||
-- name: GetListStartQuiz :many
|
||||
SELECT id FROM quiz WHERE accountid = $1 AND status = 'start';
|
||||
|
||||
-- name: GetListCreatedQuizzes :many
|
||||
SELECT id
|
||||
FROM quiz
|
||||
WHERE accountid = $1;
|
||||
|
||||
@ -901,6 +901,62 @@ func (q *Queries) GetExpiredPrivilege(ctx context.Context, privilegeid sql.NullS
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getListCreatedQuizzes = `-- name: GetListCreatedQuizzes :many
|
||||
SELECT id
|
||||
FROM quiz
|
||||
WHERE accountid = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetListCreatedQuizzes(ctx context.Context, accountid string) ([]int64, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getListCreatedQuizzes, accountid)
|
||||
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.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getListStartQuiz = `-- name: GetListStartQuiz :many
|
||||
SELECT id FROM quiz WHERE accountid = $1 AND status = 'start'
|
||||
`
|
||||
|
||||
func (q *Queries) GetListStartQuiz(ctx context.Context, accountid string) ([]int64, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getListStartQuiz, accountid)
|
||||
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.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getPrivilegesByAccountID = `-- name: GetPrivilegesByAccountID :many
|
||||
SELECT id,privilegeID,privilege_name,amount, created_at FROM privileges WHERE account_id = $1
|
||||
`
|
||||
|
||||
@ -613,3 +613,21 @@ func (r *QuizRepository) QuizMove(ctx context.Context, qID, accountID string) (s
|
||||
|
||||
return data.Qid.UUID.String(), err
|
||||
}
|
||||
|
||||
func (r *QuizRepository) GetAllQuizzesID(ctx context.Context, accountID string) ([]int64, error) {
|
||||
ids, err := r.queries.GetListCreatedQuizzes(ctx, accountID)
|
||||
if err != nil {
|
||||
return []int64{}, err
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) GetStartedQuizzesID(ctx context.Context, accountID string) ([]int64, error) {
|
||||
ids, err := r.queries.GetListStartQuiz(ctx, accountID)
|
||||
if err != nil {
|
||||
return []int64{}, err
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user