upd: added new columns in quiz_utm, and update queries with it #29
@ -1474,7 +1474,7 @@ UPDATE quiz SET gigachat = $3 WHERE id = $1 AND accountid = $2 AND deleted = fal
|
|||||||
SELECT * from quiz_utm where quizID = $1 and deleted=false;
|
SELECT * from quiz_utm where quizID = $1 and deleted=false;
|
||||||
|
|
||||||
-- name: CreateQuizUtm :one
|
-- name: CreateQuizUtm :one
|
||||||
INSERT into quiz_utm (quizID,utm) values ($1,$2) RETURNING *;
|
INSERT into quiz_utm (quizID,utm,name,category) values ($1,$2,$3,$4) RETURNING *;
|
||||||
|
|
||||||
-- name: SoftDeleteQuizUtm :exec
|
-- name: SoftDeleteQuizUtm :exec
|
||||||
UPDATE quiz_utm set deleted = true where id = $1;
|
UPDATE quiz_utm set deleted = true where id = $1;
|
||||||
|
|||||||
0
dal/schema/000028_init.down.sql
Normal file
0
dal/schema/000028_init.down.sql
Normal file
2
dal/schema/000028_init.up.sql
Normal file
2
dal/schema/000028_init.up.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER table quiz_utm add column name varchar(280) not null default '';
|
||||||
|
ALTER table quiz_utm add column category varchar(50) not null default '';
|
||||||
@ -274,6 +274,8 @@ type QuizUtm struct {
|
|||||||
Utm string `db:"utm" json:"utm"`
|
Utm string `db:"utm" json:"utm"`
|
||||||
Deleted bool `db:"deleted" json:"deleted"`
|
Deleted bool `db:"deleted" json:"deleted"`
|
||||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Category string `db:"category" json:"category"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RespondentState struct {
|
type RespondentState struct {
|
||||||
|
|||||||
@ -1191,16 +1191,23 @@ func (q *Queries) CreateQuizAudience(ctx context.Context, arg CreateQuizAudience
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createQuizUtm = `-- name: CreateQuizUtm :one
|
const createQuizUtm = `-- name: CreateQuizUtm :one
|
||||||
INSERT into quiz_utm (quizID,utm) values ($1,$2) RETURNING id, quizid, utm, deleted, created_at
|
INSERT into quiz_utm (quizID,utm,name,category) values ($1,$2,$3,$4) RETURNING id, quizid, utm, deleted, created_at, name, category
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateQuizUtmParams struct {
|
type CreateQuizUtmParams struct {
|
||||||
Quizid int64 `db:"quizid" json:"quizid"`
|
Quizid int64 `db:"quizid" json:"quizid"`
|
||||||
Utm string `db:"utm" json:"utm"`
|
Utm string `db:"utm" json:"utm"`
|
||||||
|
Name string `db:"name" json:"name"`
|
||||||
|
Category string `db:"category" json:"category"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateQuizUtm(ctx context.Context, arg CreateQuizUtmParams) (QuizUtm, error) {
|
func (q *Queries) CreateQuizUtm(ctx context.Context, arg CreateQuizUtmParams) (QuizUtm, error) {
|
||||||
row := q.db.QueryRowContext(ctx, createQuizUtm, arg.Quizid, arg.Utm)
|
row := q.db.QueryRowContext(ctx, createQuizUtm,
|
||||||
|
arg.Quizid,
|
||||||
|
arg.Utm,
|
||||||
|
arg.Name,
|
||||||
|
arg.Category,
|
||||||
|
)
|
||||||
var i QuizUtm
|
var i QuizUtm
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
@ -1208,6 +1215,8 @@ func (q *Queries) CreateQuizUtm(ctx context.Context, arg CreateQuizUtmParams) (Q
|
|||||||
&i.Utm,
|
&i.Utm,
|
||||||
&i.Deleted,
|
&i.Deleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
|
&i.Name,
|
||||||
|
&i.Category,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@ -2028,7 +2037,7 @@ func (q *Queries) GetAllCompanyUsers(ctx context.Context, amoid int32) ([]Usersa
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAllQuizUtms = `-- name: GetAllQuizUtms :many
|
const getAllQuizUtms = `-- name: GetAllQuizUtms :many
|
||||||
SELECT id, quizid, utm, deleted, created_at from quiz_utm where quizID = $1 and deleted=false
|
SELECT id, quizid, utm, deleted, created_at, name, category from quiz_utm where quizID = $1 and deleted=false
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetAllQuizUtms(ctx context.Context, quizid int64) ([]QuizUtm, error) {
|
func (q *Queries) GetAllQuizUtms(ctx context.Context, quizid int64) ([]QuizUtm, error) {
|
||||||
@ -2046,6 +2055,8 @@ func (q *Queries) GetAllQuizUtms(ctx context.Context, quizid int64) ([]QuizUtm,
|
|||||||
&i.Utm,
|
&i.Utm,
|
||||||
&i.Deleted,
|
&i.Deleted,
|
||||||
&i.CreatedAt,
|
&i.CreatedAt,
|
||||||
|
&i.Name,
|
||||||
|
&i.Category,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -4816,7 +4827,8 @@ SELECT
|
|||||||
a.question_id,
|
a.question_id,
|
||||||
a.content AS last_answer_content,
|
a.content AS last_answer_content,
|
||||||
a.result,
|
a.result,
|
||||||
a.start
|
a.start,
|
||||||
|
a.session
|
||||||
FROM
|
FROM
|
||||||
QuizAnswers a
|
QuizAnswers a
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
@ -4834,6 +4846,7 @@ SELECT
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
question_id, session
|
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
|
||||||
|
WHERE a.start = FALSE
|
||||||
),
|
),
|
||||||
Questions AS (
|
Questions AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -4846,7 +4859,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
question q
|
question q
|
||||||
JOIN LastContent lc ON q.id = lc.question_id
|
JOIN LastContent lc ON q.id = lc.question_id
|
||||||
JOIN answer a ON q.id = a.question_id
|
JOIN answer a ON q.id = a.question_id AND a.session = lc.session
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
a.quiz_id = $1
|
||||||
AND a.start = FALSE
|
AND a.start = FALSE
|
||||||
|
|||||||
@ -361,6 +361,8 @@ type QuizUTM struct {
|
|||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
QuizID int64 `json:"quizID"`
|
QuizID int64 `json:"quizID"`
|
||||||
UTM string `json:"utm"`
|
UTM string `json:"utm"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Category string `json:"category"`
|
||||||
Deleted bool `json:"deleted"`
|
Deleted bool `json:"deleted"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -768,10 +768,12 @@ func (r *QuizRepository) UpdateGigaChatQuizFlag(ctx context.Context, quizID int6
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm string) (model.QuizUTM, error) {
|
func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm, name, category string) (model.QuizUTM, error) {
|
||||||
result, err := r.queries.CreateQuizUtm(ctx, sqlcgen.CreateQuizUtmParams{
|
result, err := r.queries.CreateQuizUtm(ctx, sqlcgen.CreateQuizUtmParams{
|
||||||
Quizid: quizID,
|
Quizid: quizID,
|
||||||
Utm: utm,
|
Utm: utm,
|
||||||
|
Name: name,
|
||||||
|
Category: category,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.QuizUTM{}, err
|
return model.QuizUTM{}, err
|
||||||
@ -781,6 +783,8 @@ func (r *QuizRepository) CreateQuizUTM(ctx context.Context, quizID int64, utm st
|
|||||||
ID: result.ID,
|
ID: result.ID,
|
||||||
QuizID: result.Quizid,
|
QuizID: result.Quizid,
|
||||||
UTM: result.Utm,
|
UTM: result.Utm,
|
||||||
|
Name: result.Name,
|
||||||
|
Category: result.Category,
|
||||||
Deleted: result.Deleted,
|
Deleted: result.Deleted,
|
||||||
CreatedAt: result.CreatedAt,
|
CreatedAt: result.CreatedAt,
|
||||||
}, nil
|
}, nil
|
||||||
@ -803,6 +807,8 @@ func (r *QuizRepository) GetAllQuizUtms(ctx context.Context, quizID int64) ([]mo
|
|||||||
ID: row.ID,
|
ID: row.ID,
|
||||||
QuizID: row.Quizid,
|
QuizID: row.Quizid,
|
||||||
UTM: row.Utm,
|
UTM: row.Utm,
|
||||||
|
Name: row.Name,
|
||||||
|
Category: row.Category,
|
||||||
Deleted: row.Deleted,
|
Deleted: row.Deleted,
|
||||||
CreatedAt: row.CreatedAt,
|
CreatedAt: row.CreatedAt,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -56,6 +56,8 @@ packages:
|
|||||||
- "./dal/schema/000026_init.down.sql"
|
- "./dal/schema/000026_init.down.sql"
|
||||||
- "./dal/schema/000027_init.up.sql"
|
- "./dal/schema/000027_init.up.sql"
|
||||||
- "./dal/schema/000027_init.down.sql"
|
- "./dal/schema/000027_init.down.sql"
|
||||||
|
- "./dal/schema/000028_init.up.sql"
|
||||||
|
- "./dal/schema/000028_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