gigachat #15
@ -33,9 +33,10 @@ INSERT INTO question (
|
||||
content,
|
||||
parent_ids,
|
||||
updated_at,
|
||||
session
|
||||
session,
|
||||
auditory
|
||||
)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)
|
||||
RETURNING id, created_at, updated_at;
|
||||
|
||||
-- name: DeleteQuestion :one
|
||||
@ -323,7 +324,7 @@ SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint,
|
||||
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC;
|
||||
|
||||
-- name: GetQuestions :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC;
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at,auditory FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC;
|
||||
|
||||
-- name: SoftDeleteResultByID :exec
|
||||
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE;
|
||||
@ -1092,12 +1093,12 @@ INSERT INTO amoContact (AccountID, AmoID, Field) VALUES ($1, $2, $3) RETURNING A
|
||||
UPDATE amoContact SET Field = $1,AmoID=$3 WHERE ID = $2;
|
||||
|
||||
-- name: GetQuestionsAI :many
|
||||
SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session FROM question q
|
||||
WHERE q.quiz_id = $1 AND (q.session = $2 OR q.session = '') AND q.deleted = FALSE
|
||||
SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session,q.auditory FROM question q
|
||||
WHERE q.quiz_id = $1 AND q.auditory = $2 AND (q.session = $3 OR q.session = '') AND q.deleted = FALSE
|
||||
ORDER BY (q.session != '') ASC, --без сессии первые потом с сессией
|
||||
q.page, --по возрастанию страницы
|
||||
q.created_at --по времени создания
|
||||
LIMIT $3 OFFSET $4;
|
||||
LIMIT $4 OFFSET $5;
|
||||
|
||||
-- name: GetQuestionsAICount :one
|
||||
SELECT COUNT(*) AS count FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE;
|
||||
|
||||
1
dal/schema/000022_init.down.sql
Normal file
1
dal/schema/000022_init.down.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE question DROP COLUMN IF EXISTS auditory;
|
||||
1
dal/schema/000022_init.up.sql
Normal file
1
dal/schema/000022_init.up.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE question ADD COLUMN auditory BIGINT NOT NULL DEFAULT 0;
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// sqlc v1.29.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// sqlc v1.29.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
@ -167,6 +167,7 @@ type Gigachataudience struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Leadtarget struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
@ -222,6 +223,7 @@ type Question struct {
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Session string `db:"session" json:"session"`
|
||||
Auditory int64 `db:"auditory" json:"auditory"`
|
||||
}
|
||||
|
||||
type Quiz struct {
|
||||
@ -256,6 +258,17 @@ type Quiz struct {
|
||||
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
||||
}
|
||||
|
||||
type RespondentState struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
TelegramID int32 `db:"telegram_id" json:"telegram_id"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
State int64 `db:"state" json:"state"`
|
||||
Lang string `db:"lang" json:"lang"`
|
||||
Contact string `db:"contact" json:"contact"`
|
||||
Finish bool `db:"finish" json:"finish"`
|
||||
Session sql.NullString `db:"session" json:"session"`
|
||||
}
|
||||
|
||||
type Rule struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
@ -305,6 +318,37 @@ type Tag struct {
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type TelegramIntegration struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
BotToken string `db:"bot_token" json:"bot_token"`
|
||||
BotName string `db:"bot_name" json:"bot_name"`
|
||||
Repeatable sql.NullBool `db:"repeatable" json:"repeatable"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Status interface{} `db:"status" json:"status"`
|
||||
InstanceID int32 `db:"instance_id" json:"instance_id"`
|
||||
}
|
||||
|
||||
type TelegramIntegrationInstance struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Checkout int64 `db:"checkout" json:"checkout"`
|
||||
Limited int32 `db:"limited" json:"limited"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
}
|
||||
|
||||
type TelegramUserQuizResult struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
BotID int64 `db:"bot_id" json:"bot_id"`
|
||||
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||
CurrentField sql.NullString `db:"current_field" json:"current_field"`
|
||||
UserAnswer sql.NullString `db:"user_answer" json:"user_answer"`
|
||||
State interface{} `db:"state" json:"state"`
|
||||
Session string `db:"session" json:"session"`
|
||||
QuestionID int64 `db:"question_id" json:"question_id"`
|
||||
Iter int32 `db:"iter" json:"iter"`
|
||||
}
|
||||
|
||||
type Tgaccount struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Apiid int32 `db:"apiid" json:"apiid"`
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// sqlc v1.29.0
|
||||
// source: queries.sql
|
||||
|
||||
package sqlcgen
|
||||
@ -1078,7 +1078,6 @@ func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountPara
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
const createBitrixAccount = `-- name: CreateBitrixAccount :exec
|
||||
INSERT INTO BitrixAccounts (AccountID, BitrixID, Subdomain)
|
||||
VALUES ($1, $2, $3)
|
||||
@ -1100,10 +1099,6 @@ INSERT INTO BitrixTokens (AccountID, RefreshToken, AccessToken, AuthCode, Expira
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
const createQuizAudience = `-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID
|
||||
`
|
||||
|
||||
type CreateBitrixWebHookParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||
@ -1159,6 +1154,23 @@ func (q *Queries) CreateLeadTarget(ctx context.Context, arg CreateLeadTargetPara
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createQuizAudience = `-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID
|
||||
`
|
||||
|
||||
type CreateQuizAudienceParams struct {
|
||||
Quizid int64 `db:"quizid" json:"quizid"`
|
||||
Sex bool `db:"sex" json:"sex"`
|
||||
Age string `db:"age" json:"age"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateQuizAudience(ctx context.Context, arg CreateQuizAudienceParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, createQuizAudience, arg.Quizid, arg.Sex, arg.Age)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createTgAccount = `-- name: CreateTgAccount :one
|
||||
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
||||
VALUES ($1, $2, $3, $4, $5) RETURNING id
|
||||
@ -1327,7 +1339,7 @@ func (q *Queries) DeletePrivilegeByID(ctx context.Context, id int32) error {
|
||||
}
|
||||
|
||||
const deleteQuestion = `-- name: DeleteQuestion :one
|
||||
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at, question.session
|
||||
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at, question.session, question.auditory
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
||||
@ -1348,6 +1360,7 @@ func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -2878,7 +2891,7 @@ func (q *Queries) GetQidOwner(ctx context.Context, qid uuid.NullUUID) (string, e
|
||||
}
|
||||
|
||||
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session FROM question WHERE question.id = $1 OR question.id = ANY(
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session, auditory FROM question WHERE question.id = $1 OR question.id = ANY(
|
||||
SELECT unnest(parent_ids) FROM question WHERE id = $1
|
||||
) ORDER BY question.id DESC LIMIT $2 OFFSET $3
|
||||
`
|
||||
@ -2913,6 +2926,7 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2928,7 +2942,7 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
||||
}
|
||||
|
||||
const getQuestionListByIDs = `-- name: GetQuestionListByIDs :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session, auditory FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
||||
`
|
||||
|
||||
func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([]Question, error) {
|
||||
@ -2955,6 +2969,7 @@ func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2987,7 +3002,7 @@ func (q *Queries) GetQuestionTitle(ctx context.Context, id int64) (GetQuestionTi
|
||||
}
|
||||
|
||||
const getQuestions = `-- name: GetQuestions :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at,auditory FROM question WHERE quiz_id = $1 AND deleted = FALSE ORDER BY page ASC
|
||||
`
|
||||
|
||||
type GetQuestionsRow struct {
|
||||
@ -3004,6 +3019,7 @@ type GetQuestionsRow struct {
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Auditory int64 `db:"auditory" json:"auditory"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestionsRow, error) {
|
||||
@ -3029,6 +3045,7 @@ func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestion
|
||||
pq.Array(&i.ParentIds),
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3044,16 +3061,17 @@ func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestion
|
||||
}
|
||||
|
||||
const getQuestionsAI = `-- name: GetQuestionsAI :many
|
||||
SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session FROM question q
|
||||
WHERE q.quiz_id = $1 AND (q.session = $2 OR q.session = '') AND q.deleted = FALSE
|
||||
SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session,q.auditory FROM question q
|
||||
WHERE q.quiz_id = $1 AND q.auditory = $2 AND (q.session = $3 OR q.session = '') AND q.deleted = FALSE
|
||||
ORDER BY (q.session != '') ASC, --без сессии первые потом с сессией
|
||||
q.page, --по возрастанию страницы
|
||||
q.created_at --по времени создания
|
||||
LIMIT $3 OFFSET $4
|
||||
LIMIT $4 OFFSET $5
|
||||
`
|
||||
|
||||
type GetQuestionsAIParams struct {
|
||||
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||
Auditory int64 `db:"auditory" json:"auditory"`
|
||||
Session string `db:"session" json:"session"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
@ -3062,6 +3080,7 @@ type GetQuestionsAIParams struct {
|
||||
func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) ([]Question, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getQuestionsAI,
|
||||
arg.QuizID,
|
||||
arg.Auditory,
|
||||
arg.Session,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
@ -3088,6 +3107,7 @@ func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams)
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3903,19 +3923,6 @@ func (q *Queries) GetUserUsersByID(ctx context.Context, amoid int32) ([]Usersamo
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUsersCount = `-- name: GetUsersCount :one
|
||||
WITH user_data AS (
|
||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||
)
|
||||
SELECT COUNT(*) FROM usersAmo u JOIN user_data a ON u.AmoID = a.AmoID WHERE u.Deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersCount(ctx context.Context, accountid string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUsersCount, accountid)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
const getUserUsersByIDBitrix = `-- name: GetUserUsersByIDBitrix :many
|
||||
SELECT id, accountid, bitrixiduserid, name, lastname, secondname, title, email, ufdepartment, workposition, deleted, createdat FROM BitrixAccountUsers WHERE accountID = $1 AND Deleted = false
|
||||
`
|
||||
@ -4028,6 +4035,19 @@ func (q *Queries) GetUsersBitrixWithPagination(ctx context.Context, arg GetUsers
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUsersCount = `-- name: GetUsersCount :one
|
||||
WITH user_data AS (
|
||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||
)
|
||||
SELECT COUNT(*) FROM usersAmo u JOIN user_data a ON u.AmoID = a.AmoID WHERE u.Deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersCount(ctx context.Context, accountid string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUsersCount, accountid)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
||||
WITH user_data AS (
|
||||
@ -4052,11 +4072,10 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetUsersWithPaginationRow
|
||||
var items []Usersamo
|
||||
for rows.Next() {
|
||||
var i GetUsersWithPaginationRow
|
||||
var i Usersamo
|
||||
if err := rows.Scan(
|
||||
&i.QuizID,
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Amouserid,
|
||||
@ -4066,7 +4085,6 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
||||
&i.Group,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -4405,9 +4423,10 @@ INSERT INTO question (
|
||||
content,
|
||||
parent_ids,
|
||||
updated_at,
|
||||
session
|
||||
session,
|
||||
auditory
|
||||
)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)
|
||||
RETURNING id, created_at, updated_at
|
||||
`
|
||||
|
||||
@ -4422,6 +4441,7 @@ type InsertQuestionParams struct {
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Session string `db:"session" json:"session"`
|
||||
Auditory int64 `db:"auditory" json:"auditory"`
|
||||
}
|
||||
|
||||
type InsertQuestionRow struct {
|
||||
@ -4442,6 +4462,7 @@ func (q *Queries) InsertQuestion(ctx context.Context, arg InsertQuestionParams)
|
||||
pq.Array(arg.ParentIds),
|
||||
arg.UpdatedAt,
|
||||
arg.Session,
|
||||
arg.Auditory,
|
||||
)
|
||||
var i InsertQuestionRow
|
||||
err := row.Scan(&i.ID, &i.CreatedAt, &i.UpdatedAt)
|
||||
@ -4615,14 +4636,14 @@ SELECT
|
||||
CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
||||
FROM
|
||||
question q
|
||||
LEFT JOIN QuizAnswers a ON q.id = a.question_id
|
||||
JOIN answer a ON q.id = a.question_id
|
||||
WHERE
|
||||
a.quiz_id = $1
|
||||
AND a.created_at >= TO_TIMESTAMP($2)
|
||||
AND a.created_at <= TO_TIMESTAMP($3)
|
||||
AND a.result = TRUE
|
||||
GROUP BY
|
||||
q.title, a.result, a.quiz_id
|
||||
q.title, a.quiz_id, a.result
|
||||
HAVING
|
||||
COUNT(*) >= 1
|
||||
),
|
||||
@ -4648,9 +4669,7 @@ SELECT
|
||||
AND created_at <= TO_TIMESTAMP($3)
|
||||
GROUP BY
|
||||
question_id, session
|
||||
) AS last_created_at_one_session ON a.session = last_created_at_one_session.session
|
||||
AND a.question_id = last_created_at_one_session.question_id
|
||||
AND a.created_at = last_created_at_one_session.last_created_at
|
||||
) AS last_created_at_one_session ON a.session = last_created_at_one_session.session AND a.question_id = last_created_at_one_session.question_id AND a.created_at = last_created_at_one_session.last_created_at
|
||||
),
|
||||
Questions AS (
|
||||
SELECT
|
||||
@ -4705,7 +4724,7 @@ type QuestionsStatisticsRow struct {
|
||||
ResultsTitle string `db:"results_title" json:"results_title"`
|
||||
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
|
||||
QuestionsTitle string `db:"questions_title" json:"questions_title"`
|
||||
QuestionsPage interface{} `db:"questions_page" json:"questions_page"`
|
||||
QuestionsPage int16 `db:"questions_page" json:"questions_page"`
|
||||
AnswerContent string `db:"answer_content" json:"answer_content"`
|
||||
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`
|
||||
}
|
||||
|
||||
@ -107,6 +107,7 @@ type Question struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
Session string `json:"session"`
|
||||
Auditory int64 `json:"auditory"`
|
||||
}
|
||||
|
||||
// Answer record of question answer
|
||||
|
||||
@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"gitea.pena/SQuiz/common/pj_errors"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ func (r *QuestionRepository) CreateQuestion(ctx context.Context, record *model.Q
|
||||
ParentIds: record.ParentIds,
|
||||
UpdatedAt: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
Session: record.Session,
|
||||
Auditory: record.Auditory,
|
||||
}
|
||||
|
||||
data, err := r.queries.InsertQuestion(ctx, params)
|
||||
@ -64,7 +65,7 @@ func (r *QuestionRepository) GetQuestionList(
|
||||
ctx context.Context,
|
||||
limit, offset, from, to, quizId uint64,
|
||||
deleted, required bool,
|
||||
search, qType string) ([]model.Question, uint64, error) {
|
||||
search, qType string, auditory int64) ([]model.Question, uint64, error) {
|
||||
query := `
|
||||
SELECT que.* FROM question as que JOIN quiz as qui on que.quiz_id = ANY(qui.parent_ids) or que.quiz_id = qui.id
|
||||
%s
|
||||
@ -110,6 +111,8 @@ func (r *QuestionRepository) GetQuestionList(
|
||||
whereClause = append(whereClause, fmt.Sprintf("to_tsvector('russian', que.title) @@ to_tsquery('russian', $%d)", len(data)))
|
||||
}
|
||||
|
||||
whereClause = append(whereClause, fmt.Sprintf("que.auditory = %d", auditory))
|
||||
|
||||
data = append(data, limit, offset)
|
||||
if len(whereClause) != 0 {
|
||||
query = fmt.Sprintf(query,
|
||||
@ -161,6 +164,7 @@ func (r *QuestionRepository) GetQuestionList(
|
||||
&piece.CreatedAt,
|
||||
&piece.UpdatedAt,
|
||||
&piece.Session,
|
||||
&piece.Auditory,
|
||||
); err != nil {
|
||||
qerr = err
|
||||
return
|
||||
@ -280,6 +284,7 @@ func (r *QuestionRepository) DeleteQuestion(ctx context.Context, id uint64) (mod
|
||||
ParentIds: row.ParentIds,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Auditory: row.Auditory,
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@ -367,6 +372,7 @@ func (r *QuestionRepository) QuestionHistory(ctx context.Context, id, limit, off
|
||||
ParentIds: row.ParentIds,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Auditory: row.Auditory,
|
||||
}
|
||||
result = append(result, record)
|
||||
}
|
||||
@ -483,6 +489,7 @@ func (r *QuestionRepository) GetQuestionListByIDs(ctx context.Context, ids []int
|
||||
ParentIds: row.ParentIds,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Auditory: row.Auditory,
|
||||
}
|
||||
|
||||
questions = append(questions, question)
|
||||
@ -491,12 +498,13 @@ func (r *QuestionRepository) GetQuestionListByIDs(ctx context.Context, ids []int
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
func (r *QuestionRepository) GetQuestionsAI(ctx context.Context, quizID int64, session string, limit, offset int32) ([]model.Question, uint64, error) {
|
||||
func (r *QuestionRepository) GetQuestionsAI(ctx context.Context, quizID int64, session string, limit, offset int32, auditory int64) ([]model.Question, uint64, error) {
|
||||
rows, err := r.queries.GetQuestionsAI(ctx, sqlcgen.GetQuestionsAIParams{
|
||||
QuizID: quizID,
|
||||
Session: session,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Auditory: auditory,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@ -521,6 +529,7 @@ func (r *QuestionRepository) GetQuestionsAI(ctx context.Context, quizID int64, s
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Session: row.Session,
|
||||
Auditory: row.Auditory,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -218,6 +218,7 @@ func (r *ResultRepository) GetQuestions(ctx context.Context, quizID uint64) ([]m
|
||||
ParentIds: row.ParentIds,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
UpdatedAt: row.UpdatedAt.Time,
|
||||
Auditory: row.Auditory,
|
||||
}
|
||||
|
||||
questions = append(questions, question)
|
||||
|
||||
@ -3,6 +3,7 @@ package statistics
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"gitea.pena/SQuiz/common/dal/sqlcgen"
|
||||
)
|
||||
|
||||
|
||||
@ -44,6 +44,8 @@ packages:
|
||||
- "./dal/schema/000020_init.down.sql"
|
||||
- "./dal/schema/000021_init.up.sql"
|
||||
- "./dal/schema/000021_init.down.sql"
|
||||
- "./dal/schema/000022_init.up.sql"
|
||||
- "./dal/schema/000022_init.down.sql"
|
||||
engine: "postgresql"
|
||||
emit_json_tags: true
|
||||
emit_db_tags: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user