added queries and table for quiz utm
This commit is contained in:
parent
ddd0219fb3
commit
a61f264ccf
@ -1466,3 +1466,12 @@ UPDATE bitrixContact SET Field = $1,BitrixID=$3 WHERE ID = $2;
|
||||
|
||||
-- name: UpdateGigaChatQuizFlag :exec
|
||||
UPDATE quiz SET gigachat = true 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;
|
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
|
||||
);
|
@ -259,6 +259,14 @@ type Quiz struct {
|
||||
Gigachat bool `db:"gigachat" json:"gigachat"`
|
||||
}
|
||||
|
||||
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 {
|
||||
ID int64 `db:"id" json:"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
|
||||
}
|
||||
|
||||
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
|
||||
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE Deleted = false
|
||||
`
|
||||
@ -5019,6 +5074,15 @@ func (q *Queries) SoftDeleteBitrixAccount(ctx context.Context, accountid string)
|
||||
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
|
||||
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
||||
`
|
||||
|
@ -349,3 +349,11 @@ var ValidLeadTargetTypes = map[string]bool{
|
||||
"telegram": 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"`
|
||||
}
|
||||
|
@ -766,3 +766,46 @@ func (r *QuizRepository) UpdateGigaChatQuizFlag(ctx context.Context, quizID int6
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ packages:
|
||||
- "./dal/schema/000023_init.down.sql"
|
||||
- "./dal/schema/000024_init.up.sql"
|
||||
- "./dal/schema/000024_init.down.sql"
|
||||
- "./dal/schema/000025_init.up.sql"
|
||||
- "./dal/schema/000025_init.down.sql"
|
||||
engine: "postgresql"
|
||||
emit_json_tags: true
|
||||
emit_db_tags: true
|
||||
|
Loading…
Reference in New Issue
Block a user