gigachat_conatraints #24
@ -1465,4 +1465,29 @@ INSERT INTO bitrixContact (AccountID, BitrixID, Field) VALUES ($1, $2, $3) RETUR
|
|||||||
UPDATE bitrixContact SET Field = $1,BitrixID=$3 WHERE ID = $2;
|
UPDATE bitrixContact SET Field = $1,BitrixID=$3 WHERE ID = $2;
|
||||||
|
|
||||||
-- name: UpdateGigaChatQuizFlag :exec
|
-- name: UpdateGigaChatQuizFlag :exec
|
||||||
UPDATE quiz SET gigachat = true where id = $1 AND accountid = $2 AND deleted = false;
|
UPDATE quiz SET gigachat = $3 WHERE id = $1 AND accountid = $2 AND deleted = false;
|
||||||
|
|
||||||
|
-- name: GetAllQuizUtms :many
|
||||||
|
SELECT * from quiz_utm where quizID = $1 and deleted=false;
|
||||||
|
|
||||||
|
-- name: CreateQuizUtm :one
|
||||||
|
INSERT into quiz_utm (quizID,utm) values ($1,$2) RETURNING *;
|
||||||
|
|
||||||
|
-- name: SoftDeleteQuizUtm :exec
|
||||||
|
UPDATE quiz_utm set deleted = true where id = $1;
|
||||||
|
|
||||||
|
-- name: GetQuizPrivilegeUsage :one
|
||||||
|
SELECT * FROM quiz_privilege_usage
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2 LIMIT 1;
|
||||||
|
|
||||||
|
-- name: InsertQuizPrivilegeUsage :one
|
||||||
|
INSERT INTO quiz_privilege_usage (quiz_id, privilege_id, used_count)
|
||||||
|
VALUES ($1, $2, 0) RETURNING *;
|
||||||
|
|
||||||
|
-- name: IncrementQuizPrivilegeUsage :exec
|
||||||
|
UPDATE quiz_privilege_usage SET used_count = used_count + 1, updated_at = CURRENT_TIMESTAMP
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2;
|
||||||
|
|
||||||
|
-- name: ResetQuizPrivilegeUsageCount :exec
|
||||||
|
UPDATE quiz_privilege_usage SET used_count = 0, updated_at = CURRENT_TIMESTAMP
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2;
|
||||||
1
dal/schema/000025_init.down.sql
Normal file
1
dal/schema/000025_init.down.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
drop table if exists quiz_utm;
|
||||||
7
dal/schema/000025_init.up.sql
Normal file
7
dal/schema/000025_init.up.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS quiz_utm (
|
||||||
|
id bigserial UNIQUE NOT NULL PRIMARY KEY,
|
||||||
|
quizID bigint not null,
|
||||||
|
utm text not null default '',
|
||||||
|
deleted boolean not null default false,
|
||||||
|
created_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
2
dal/schema/000026_init.down.sql
Normal file
2
dal/schema/000026_init.down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DROP INDEX IF EXISTS idx_quiz_privilege_unique;
|
||||||
|
drop table if exists quiz_privilege_usage;
|
||||||
10
dal/schema/000026_init.up.sql
Normal file
10
dal/schema/000026_init.up.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
CREATE TABLE quiz_privilege_usage (
|
||||||
|
id bigserial UNIQUE NOT NULL PRIMARY KEY,
|
||||||
|
quiz_id BIGINT NOT NULL REFERENCES quiz(id) ON DELETE CASCADE,
|
||||||
|
privilege_id VARCHAR(50) NOT NULL,
|
||||||
|
used_count INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX idx_quiz_privilege_unique ON quiz_privilege_usage (quiz_id, privilege_id);
|
||||||
@ -259,6 +259,23 @@ type Quiz struct {
|
|||||||
Gigachat bool `db:"gigachat" json:"gigachat"`
|
Gigachat bool `db:"gigachat" json:"gigachat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QuizPrivilegeUsage struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
PrivilegeID string `db:"privilege_id" json:"privilege_id"`
|
||||||
|
UsedCount int32 `db:"used_count" json:"used_count"`
|
||||||
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||||
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type QuizUtm struct {
|
||||||
|
ID int64 `db:"id" json:"id"`
|
||||||
|
Quizid int64 `db:"quizid" json:"quizid"`
|
||||||
|
Utm string `db:"utm" json:"utm"`
|
||||||
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type RespondentState struct {
|
type RespondentState struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
TelegramID int32 `db:"telegram_id" json:"telegram_id"`
|
TelegramID int32 `db:"telegram_id" json:"telegram_id"`
|
||||||
|
|||||||
@ -1190,6 +1190,28 @@ func (q *Queries) CreateQuizAudience(ctx context.Context, arg CreateQuizAudience
|
|||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createQuizUtm = `-- name: CreateQuizUtm :one
|
||||||
|
INSERT into quiz_utm (quizID,utm) values ($1,$2) RETURNING id, quizid, utm, deleted, created_at
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateQuizUtmParams struct {
|
||||||
|
Quizid int64 `db:"quizid" json:"quizid"`
|
||||||
|
Utm string `db:"utm" json:"utm"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateQuizUtm(ctx context.Context, arg CreateQuizUtmParams) (QuizUtm, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, createQuizUtm, arg.Quizid, arg.Utm)
|
||||||
|
var i QuizUtm
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Quizid,
|
||||||
|
&i.Utm,
|
||||||
|
&i.Deleted,
|
||||||
|
&i.CreatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const createTgAccount = `-- name: CreateTgAccount :one
|
const createTgAccount = `-- name: CreateTgAccount :one
|
||||||
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
||||||
VALUES ($1, $2, $3, $4, $5) RETURNING id
|
VALUES ($1, $2, $3, $4, $5) RETURNING id
|
||||||
@ -2005,6 +2027,39 @@ func (q *Queries) GetAllCompanyUsers(ctx context.Context, amoid int32) ([]Usersa
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllQuizUtms = `-- name: GetAllQuizUtms :many
|
||||||
|
SELECT id, quizid, utm, deleted, created_at from quiz_utm where quizID = $1 and deleted=false
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetAllQuizUtms(ctx context.Context, quizid int64) ([]QuizUtm, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getAllQuizUtms, quizid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []QuizUtm
|
||||||
|
for rows.Next() {
|
||||||
|
var i QuizUtm
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Quizid,
|
||||||
|
&i.Utm,
|
||||||
|
&i.Deleted,
|
||||||
|
&i.CreatedAt,
|
||||||
|
); 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 getAllTgAccounts = `-- name: GetAllTgAccounts :many
|
const getAllTgAccounts = `-- name: GetAllTgAccounts :many
|
||||||
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE Deleted = false
|
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE Deleted = false
|
||||||
`
|
`
|
||||||
@ -3395,6 +3450,30 @@ func (q *Queries) GetQuizHistory(ctx context.Context, arg GetQuizHistoryParams)
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getQuizPrivilegeUsage = `-- name: GetQuizPrivilegeUsage :one
|
||||||
|
SELECT id, quiz_id, privilege_id, used_count, created_at, updated_at FROM quiz_privilege_usage
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2 LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetQuizPrivilegeUsageParams struct {
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
PrivilegeID string `db:"privilege_id" json:"privilege_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetQuizPrivilegeUsage(ctx context.Context, arg GetQuizPrivilegeUsageParams) (QuizPrivilegeUsage, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getQuizPrivilegeUsage, arg.QuizID, arg.PrivilegeID)
|
||||||
|
var i QuizPrivilegeUsage
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.QuizID,
|
||||||
|
&i.PrivilegeID,
|
||||||
|
&i.UsedCount,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const getQuizRule = `-- name: GetQuizRule :one
|
const getQuizRule = `-- name: GetQuizRule :one
|
||||||
SELECT id, accountid, quizid, performerid, pipelineid, stepid, fieldsrule, deleted, createdat, tagstoadd FROM rules WHERE QuizID = $1 AND AccountID = (SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $2 AND accountsAmo.Deleted = false) AND Deleted = false
|
SELECT id, accountid, quizid, performerid, pipelineid, stepid, fieldsrule, deleted, createdat, tagstoadd FROM rules WHERE QuizID = $1 AND AccountID = (SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $2 AND accountsAmo.Deleted = false) AND Deleted = false
|
||||||
`
|
`
|
||||||
@ -4317,6 +4396,21 @@ func (q *Queries) GettingBitrixUsersTrueResults(ctx context.Context) ([]GettingB
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incrementQuizPrivilegeUsage = `-- name: IncrementQuizPrivilegeUsage :exec
|
||||||
|
UPDATE quiz_privilege_usage SET used_count = used_count + 1, updated_at = CURRENT_TIMESTAMP
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type IncrementQuizPrivilegeUsageParams struct {
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
PrivilegeID string `db:"privilege_id" json:"privilege_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) IncrementQuizPrivilegeUsage(ctx context.Context, arg IncrementQuizPrivilegeUsageParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, incrementQuizPrivilegeUsage, arg.QuizID, arg.PrivilegeID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const insertAnswers = `-- name: InsertAnswers :one
|
const insertAnswers = `-- name: InsertAnswers :one
|
||||||
INSERT INTO answer(
|
INSERT INTO answer(
|
||||||
content,
|
content,
|
||||||
@ -4599,6 +4693,30 @@ func (q *Queries) InsertQuiz(ctx context.Context, arg InsertQuizParams) (InsertQ
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const insertQuizPrivilegeUsage = `-- name: InsertQuizPrivilegeUsage :one
|
||||||
|
INSERT INTO quiz_privilege_usage (quiz_id, privilege_id, used_count)
|
||||||
|
VALUES ($1, $2, 0) RETURNING id, quiz_id, privilege_id, used_count, created_at, updated_at
|
||||||
|
`
|
||||||
|
|
||||||
|
type InsertQuizPrivilegeUsageParams struct {
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
PrivilegeID string `db:"privilege_id" json:"privilege_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) InsertQuizPrivilegeUsage(ctx context.Context, arg InsertQuizPrivilegeUsageParams) (QuizPrivilegeUsage, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, insertQuizPrivilegeUsage, arg.QuizID, arg.PrivilegeID)
|
||||||
|
var i QuizPrivilegeUsage
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.QuizID,
|
||||||
|
&i.PrivilegeID,
|
||||||
|
&i.UsedCount,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.UpdatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const moveToHistory = `-- name: MoveToHistory :one
|
const moveToHistory = `-- name: MoveToHistory :one
|
||||||
INSERT INTO question(
|
INSERT INTO question(
|
||||||
quiz_id, title, description, questiontype, required,
|
quiz_id, title, description, questiontype, required,
|
||||||
@ -4840,6 +4958,21 @@ func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizC
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resetQuizPrivilegeUsageCount = `-- name: ResetQuizPrivilegeUsageCount :exec
|
||||||
|
UPDATE quiz_privilege_usage SET used_count = 0, updated_at = CURRENT_TIMESTAMP
|
||||||
|
WHERE quiz_id = $1 AND privilege_id = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type ResetQuizPrivilegeUsageCountParams struct {
|
||||||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||||
|
PrivilegeID string `db:"privilege_id" json:"privilege_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) ResetQuizPrivilegeUsageCount(ctx context.Context, arg ResetQuizPrivilegeUsageCountParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, resetQuizPrivilegeUsageCount, arg.QuizID, arg.PrivilegeID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const searchIDByAppIDanAppHash = `-- name: SearchIDByAppIDanAppHash :one
|
const searchIDByAppIDanAppHash = `-- name: SearchIDByAppIDanAppHash :one
|
||||||
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE ApiID = $1 and ApiHash=$2 and Deleted = false
|
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE ApiID = $1 and ApiHash=$2 and Deleted = false
|
||||||
`
|
`
|
||||||
@ -5019,6 +5152,15 @@ func (q *Queries) SoftDeleteBitrixAccount(ctx context.Context, accountid string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const softDeleteQuizUtm = `-- name: SoftDeleteQuizUtm :exec
|
||||||
|
UPDATE quiz_utm set deleted = true where id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) SoftDeleteQuizUtm(ctx context.Context, id int64) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, softDeleteQuizUtm, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
||||||
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
||||||
`
|
`
|
||||||
@ -5286,16 +5428,17 @@ func (q *Queries) UpdateFields(ctx context.Context, dollar_1 json.RawMessage) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateGigaChatQuizFlag = `-- name: UpdateGigaChatQuizFlag :exec
|
const updateGigaChatQuizFlag = `-- name: UpdateGigaChatQuizFlag :exec
|
||||||
UPDATE quiz SET gigachat = true where id = $1 AND accountid = $2 AND deleted = false
|
UPDATE quiz SET gigachat = $3 WHERE id = $1 AND accountid = $2 AND deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateGigaChatQuizFlagParams struct {
|
type UpdateGigaChatQuizFlagParams struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Accountid string `db:"accountid" json:"accountid"`
|
Accountid string `db:"accountid" json:"accountid"`
|
||||||
|
Gigachat bool `db:"gigachat" json:"gigachat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) UpdateGigaChatQuizFlag(ctx context.Context, arg UpdateGigaChatQuizFlagParams) error {
|
func (q *Queries) UpdateGigaChatQuizFlag(ctx context.Context, arg UpdateGigaChatQuizFlagParams) error {
|
||||||
_, err := q.db.ExecContext(ctx, updateGigaChatQuizFlag, arg.ID, arg.Accountid)
|
_, err := q.db.ExecContext(ctx, updateGigaChatQuizFlag, arg.ID, arg.Accountid, arg.Gigachat)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,8 @@ const (
|
|||||||
TypeResult = "result"
|
TypeResult = "result"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const QuizGigaChatPrivilegeLimitUsage = 30
|
||||||
|
|
||||||
// Quiz is a struct for set up an quiz settings
|
// Quiz is a struct for set up an quiz settings
|
||||||
type Quiz struct {
|
type Quiz struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
@ -349,3 +351,20 @@ var ValidLeadTargetTypes = map[string]bool{
|
|||||||
"telegram": true,
|
"telegram": true,
|
||||||
"whatsapp": true,
|
"whatsapp": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QuizUTM struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
QuizID int64 `json:"quizID"`
|
||||||
|
UTM string `json:"utm"`
|
||||||
|
Deleted bool `json:"deleted"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type QuizUsagePrivilege struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
QuizID int64 `json:"quiz_id"`
|
||||||
|
PrivilegeID string `json:"privilege_id"`
|
||||||
|
UsedCount int32 `json:"used_count"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|||||||
@ -756,13 +756,108 @@ func (r *QuizRepository) CheckQuizOwner(ctx context.Context, accountID string, q
|
|||||||
return id == accountID, nil
|
return id == accountID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *QuizRepository) UpdateGigaChatQuizFlag(ctx context.Context, quizID int64, accountID string) error {
|
func (r *QuizRepository) UpdateGigaChatQuizFlag(ctx context.Context, quizID int64, accountID string, flag bool) error {
|
||||||
err := r.queries.UpdateGigaChatQuizFlag(ctx, sqlcgen.UpdateGigaChatQuizFlagParams{
|
err := r.queries.UpdateGigaChatQuizFlag(ctx, sqlcgen.UpdateGigaChatQuizFlagParams{
|
||||||
ID: quizID,
|
ID: quizID,
|
||||||
Accountid: accountID,
|
Accountid: accountID,
|
||||||
|
Gigachat: flag,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm string) (model.QuizUTM, error) {
|
||||||
|
result, err := r.queries.CreateQuizUtm(ctx, sqlcgen.CreateQuizUtmParams{
|
||||||
|
Quizid: quizID,
|
||||||
|
Utm: utm,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return model.QuizUTM{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return model.QuizUTM{
|
||||||
|
ID: result.ID,
|
||||||
|
QuizID: result.Quizid,
|
||||||
|
UTM: result.Utm,
|
||||||
|
Deleted: result.Deleted,
|
||||||
|
CreatedAt: result.CreatedAt,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) DeleteQuizUTM(ctx context.Context, utmID int64) error {
|
||||||
|
return r.queries.SoftDeleteQuizUtm(ctx, utmID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) GetAllQuizUtms(ctx context.Context, quizID int64) ([]model.QuizUTM, error) {
|
||||||
|
rows, err := r.queries.GetAllQuizUtms(ctx, quizID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]model.QuizUTM, 0, len(rows))
|
||||||
|
|
||||||
|
for _, row := range rows {
|
||||||
|
result = append(result, model.QuizUTM{
|
||||||
|
ID: row.ID,
|
||||||
|
QuizID: row.Quizid,
|
||||||
|
UTM: row.Utm,
|
||||||
|
Deleted: row.Deleted,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) GetQuizPrivilegeUsage(ctx context.Context, quizID int64, privilegeID string) (*model.QuizUsagePrivilege, error) {
|
||||||
|
usage, err := r.queries.GetQuizPrivilegeUsage(ctx, sqlcgen.GetQuizPrivilegeUsageParams{
|
||||||
|
QuizID: quizID,
|
||||||
|
PrivilegeID: privilegeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
return nil, nil // нет записи не ошибка
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &model.QuizUsagePrivilege{
|
||||||
|
ID: usage.ID,
|
||||||
|
QuizID: usage.QuizID,
|
||||||
|
PrivilegeID: usage.PrivilegeID,
|
||||||
|
CreatedAt: usage.CreatedAt,
|
||||||
|
UpdatedAt: usage.UpdatedAt,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) InsertQuizPrivilegeUsage(ctx context.Context, quizID int64, privilegeID string) (*model.QuizUsagePrivilege, error) {
|
||||||
|
usage, err := r.queries.InsertQuizPrivilegeUsage(ctx, sqlcgen.InsertQuizPrivilegeUsageParams{
|
||||||
|
QuizID: quizID,
|
||||||
|
PrivilegeID: privilegeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &model.QuizUsagePrivilege{
|
||||||
|
ID: usage.ID,
|
||||||
|
QuizID: usage.QuizID,
|
||||||
|
PrivilegeID: usage.PrivilegeID,
|
||||||
|
CreatedAt: usage.CreatedAt,
|
||||||
|
UpdatedAt: usage.UpdatedAt,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) IncrementQuizPrivilegeUsage(ctx context.Context, quizID int64, privilegeID string) error {
|
||||||
|
return r.queries.IncrementQuizPrivilegeUsage(ctx, sqlcgen.IncrementQuizPrivilegeUsageParams{
|
||||||
|
QuizID: quizID,
|
||||||
|
PrivilegeID: privilegeID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *QuizRepository) ResetQuizPrivilegeUsageCount(ctx context.Context, quizID int64, privilegeID string) error {
|
||||||
|
return r.queries.ResetQuizPrivilegeUsageCount(ctx, sqlcgen.ResetQuizPrivilegeUsageCountParams{
|
||||||
|
QuizID: quizID,
|
||||||
|
PrivilegeID: privilegeID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -50,6 +50,10 @@ packages:
|
|||||||
- "./dal/schema/000023_init.down.sql"
|
- "./dal/schema/000023_init.down.sql"
|
||||||
- "./dal/schema/000024_init.up.sql"
|
- "./dal/schema/000024_init.up.sql"
|
||||||
- "./dal/schema/000024_init.down.sql"
|
- "./dal/schema/000024_init.down.sql"
|
||||||
|
- "./dal/schema/000025_init.up.sql"
|
||||||
|
- "./dal/schema/000025_init.down.sql"
|
||||||
|
- "./dal/schema/000026_init.up.sql"
|
||||||
|
- "./dal/schema/000026_init.down.sql"
|
||||||
engine: "postgresql"
|
engine: "postgresql"
|
||||||
emit_json_tags: true
|
emit_json_tags: true
|
||||||
emit_db_tags: true
|
emit_db_tags: true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user