ai for imp
This commit is contained in:
parent
0360146b10
commit
802ffdfd07
@ -32,9 +32,10 @@ INSERT INTO question (
|
||||
page,
|
||||
content,
|
||||
parent_ids,
|
||||
updated_at
|
||||
updated_at,
|
||||
session
|
||||
)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||
RETURNING id, created_at, updated_at;
|
||||
|
||||
-- name: DeleteQuestion :one
|
||||
@ -1052,3 +1053,12 @@ INSERT INTO amoContact (AccountID, AmoID, Field) VALUES ($1, $2, $3) RETURNING A
|
||||
|
||||
-- name: UpdateAmoContact :exec
|
||||
UPDATE amoContact SET Field = $1,AmoID=$3 WHERE ID = $2;
|
||||
|
||||
-- name: GetQuestionsAI :many
|
||||
WITH total_count AS (SELECT COUNT(*) AS count
|
||||
FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE)
|
||||
SELECT q.*, t.count FROM question q
|
||||
CROSS JOIN total_count t
|
||||
WHERE q.quiz_id = $1 AND (q.session = $2 OR q.session = '') AND q.deleted = FALSE
|
||||
ORDER BY q.page, q.created_at ASC LIMIT $3 OFFSET $4;
|
||||
|
||||
|
1
dal/schema/000017_init.down.sql
Normal file
1
dal/schema/000017_init.down.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER table question DROP column session;
|
11
dal/schema/000017_init.up.sql
Normal file
11
dal/schema/000017_init.up.sql
Normal file
@ -0,0 +1,11 @@
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_enum
|
||||
WHERE enumlabel = 'ai' AND enumtypid = 'quiz_status'::regtype
|
||||
) THEN
|
||||
ALTER TYPE quiz_status ADD VALUE 'ai';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE question ADD column session varchar(20) NOT NULL DEFAULT '';
|
@ -13,6 +13,7 @@ const (
|
||||
StatusStart = "start"
|
||||
StatusTimeout = "timeout"
|
||||
StatusOffLimit = "offlimit"
|
||||
StatusAI = "ai"
|
||||
|
||||
TypeVariant = "variant"
|
||||
TypeImages = "images"
|
||||
@ -104,6 +105,8 @@ type Question struct {
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
Session string `json:"session"`
|
||||
}
|
||||
|
||||
// Answer record of question answer
|
||||
|
@ -43,6 +43,7 @@ func (r *QuestionRepository) CreateQuestion(ctx context.Context, record *model.Q
|
||||
Content: sql.NullString{String: record.Content, Valid: true},
|
||||
ParentIds: record.ParentIds,
|
||||
UpdatedAt: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
Session: record.Session,
|
||||
}
|
||||
|
||||
data, err := r.queries.InsertQuestion(ctx, params)
|
||||
@ -485,3 +486,41 @@ 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) {
|
||||
rows, err := r.queries.GetQuestionsAI(ctx, sqlcgen.GetQuestionsAIParams{
|
||||
QuizID: quizID,
|
||||
Session: session,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var questions []model.Question
|
||||
var count uint64
|
||||
|
||||
for _, row := range rows {
|
||||
count = uint64(row.Count)
|
||||
|
||||
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,
|
||||
Session: row.Session,
|
||||
})
|
||||
}
|
||||
|
||||
return questions, count, nil
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ packages:
|
||||
- "./dal/schema/000014_init.down.sql"
|
||||
- "./dal/schema/000016_init.up.sql"
|
||||
- "./dal/schema/000016_init.down.sql"
|
||||
- "./dal/schema/000017_init.up.sql"
|
||||
- "./dal/schema/000017_init.down.sql"
|
||||
engine: "postgresql"
|
||||
emit_json_tags: true
|
||||
emit_db_tags: true
|
||||
|
Loading…
Reference in New Issue
Block a user