Merge branch 'tmplCopy' into 'main'
Методы копирования шаблонного опроса на свой аккаунт See merge request backend/quiz/common!13
This commit is contained in:
commit
ad8f46c9e7
@ -656,3 +656,17 @@ SELECT id FROM quiz WHERE accountid = $1 AND status = 'start';
|
||||
SELECT id
|
||||
FROM quiz
|
||||
WHERE accountid = $1;
|
||||
|
||||
-- name: TemplateCopy :exec
|
||||
WITH copied_quiz AS (
|
||||
INSERT INTO quiz (accountid, name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids)
|
||||
SELECT $1 AS accountid,name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, 'stop' AS status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids
|
||||
FROM quiz
|
||||
WHERE qid = $2
|
||||
RETURNING id
|
||||
)
|
||||
INSERT INTO question (quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids)
|
||||
SELECT cq.id AS quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids
|
||||
FROM question q
|
||||
JOIN quiz old ON q.quiz_id = old.id
|
||||
JOIN copied_quiz cq ON old.qid = $2;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.25.0
|
||||
// sqlc v1.26.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.25.0
|
||||
// sqlc v1.26.0
|
||||
|
||||
package sqlcgen
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.25.0
|
||||
// sqlc v1.26.0
|
||||
// source: queries.sql
|
||||
|
||||
package sqlcgen
|
||||
@ -1916,6 +1916,31 @@ func (q *Queries) SoftDeleteResultByID(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const templateCopy = `-- name: TemplateCopy :exec
|
||||
WITH copied_quiz AS (
|
||||
INSERT INTO quiz (accountid, name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids)
|
||||
SELECT $1 AS accountid,name,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,super,group_id, description, config, 'stop' AS status,limit_answers,due_to,time_of_passing,pausable,version,version_comment, parent_ids
|
||||
FROM quiz
|
||||
WHERE qid = $2
|
||||
RETURNING id
|
||||
)
|
||||
INSERT INTO question (quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids)
|
||||
SELECT cq.id AS quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids
|
||||
FROM question q
|
||||
JOIN quiz old ON q.quiz_id = old.id
|
||||
JOIN copied_quiz cq ON old.qid = $2
|
||||
`
|
||||
|
||||
type TemplateCopyParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||||
}
|
||||
|
||||
func (q *Queries) TemplateCopy(ctx context.Context, arg TemplateCopyParams) error {
|
||||
_, err := q.db.ExecContext(ctx, templateCopy, arg.Accountid, arg.Qid)
|
||||
return err
|
||||
}
|
||||
|
||||
const updatePrivilege = `-- name: UpdatePrivilege :exec
|
||||
UPDATE privileges SET amount = $1, created_at = $2 WHERE account_id = $3 AND privilegeID = $4
|
||||
`
|
||||
|
||||
@ -412,12 +412,12 @@ func (r *QuizRepository) UpdateQuiz(ctx context.Context, accountId string, recor
|
||||
|
||||
params = append(params, record.GroupId, record.Version, record.Id, accountId)
|
||||
var placeholders []any
|
||||
for i:=1;i<=len(params);i++ {
|
||||
for i := 1; i <= len(params); i++ {
|
||||
placeholders = append(placeholders, i)
|
||||
}
|
||||
|
||||
query = fmt.Sprintf(query, placeholders...)
|
||||
|
||||
|
||||
_, err := r.pool.ExecContext(ctx, query, params...)
|
||||
return err
|
||||
}
|
||||
@ -631,3 +631,23 @@ func (r *QuizRepository) GetStartedQuizzesID(ctx context.Context, accountID stri
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (r *QuizRepository) TemplateCopy(ctx context.Context, accountID, qID string) error {
|
||||
qUUID, err := uuid.Parse(qID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
qNullUUID := uuid.NullUUID{UUID: qUUID, Valid: true}
|
||||
|
||||
err = r.queries.TemplateCopy(ctx, sqlcgen.TemplateCopyParams{
|
||||
Accountid: accountID,
|
||||
Qid: qNullUUID,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user