Merge branch 'leadTarget' into 'main'
Lead target See merge request backend/quiz/common!35
This commit is contained in:
commit
2415bd7db2
@ -13,8 +13,6 @@ type Deps struct {
|
||||
SmtpHost string
|
||||
SmtpPort string
|
||||
SmtpSender string
|
||||
Username string
|
||||
Password string
|
||||
ApiKey string
|
||||
FiberClient *fiber.Client
|
||||
}
|
||||
@ -24,8 +22,6 @@ type SmtpClient struct {
|
||||
smtpHost string
|
||||
smtpPort string
|
||||
smtpSender string
|
||||
username string
|
||||
password string
|
||||
apiKey string
|
||||
fiberClient *fiber.Client
|
||||
}
|
||||
@ -39,8 +35,6 @@ func NewSmtpClient(deps Deps) *SmtpClient {
|
||||
smtpHost: deps.SmtpHost,
|
||||
smtpPort: deps.SmtpPort,
|
||||
smtpSender: deps.SmtpSender,
|
||||
username: deps.Username,
|
||||
password: deps.Password,
|
||||
apiKey: deps.ApiKey,
|
||||
fiberClient: deps.FiberClient,
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/quiz"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/result"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/statistics"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/tg"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/workers"
|
||||
"time"
|
||||
)
|
||||
@ -34,6 +35,7 @@ type DAL struct {
|
||||
WorkerRepo *workers.WorkerRepository
|
||||
StatisticsRepo *statistics.StatisticsRepository
|
||||
WorkerAnsRepo *answer.WorkerAnswerRepository
|
||||
TgRepo *tg.TgRepo
|
||||
}
|
||||
|
||||
func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, error) {
|
||||
@ -100,6 +102,11 @@ func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, err
|
||||
Pool: pool,
|
||||
})
|
||||
|
||||
tgRepo := tg.NewTgRepo(tg.Deps{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
})
|
||||
|
||||
return &DAL{
|
||||
conn: pool,
|
||||
queries: queries,
|
||||
@ -111,6 +118,7 @@ func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, err
|
||||
WorkerRepo: workerRepo,
|
||||
StatisticsRepo: statisticsRepo,
|
||||
WorkerAnsRepo: workerAnsRepo,
|
||||
TgRepo: tgRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,6 @@ SELECT
|
||||
p.amount,
|
||||
p.created_at,
|
||||
a.id,
|
||||
a.email,
|
||||
qz.config
|
||||
FROM
|
||||
privileges AS p
|
||||
@ -144,7 +143,7 @@ WHERE
|
||||
qz.id = $1;
|
||||
|
||||
-- name: CreateAccount :one
|
||||
INSERT INTO account (id, user_id, email, created_at, deleted) VALUES ($1, $2, $3, $4, $5) RETURNING *;;
|
||||
INSERT INTO account (id, user_id, created_at, deleted) VALUES ($1, $2, $3, $4) RETURNING *;
|
||||
|
||||
-- name: DeletePrivilegeByAccID :exec
|
||||
DELETE FROM privileges WHERE account_id = $1;
|
||||
@ -248,7 +247,6 @@ UPDATE privileges SET amount = $1 WHERE id = $2;
|
||||
SELECT
|
||||
a.id,
|
||||
a.user_id,
|
||||
a.email,
|
||||
a.created_at,
|
||||
COALESCE(p.ID,0),
|
||||
coalesce(p.privilegeid,''),
|
||||
@ -1057,3 +1055,31 @@ 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: CreateLeadTarget :one
|
||||
INSERT INTO leadtarget (accountID,type,quizID,target,InviteLink) VALUES ($1,$2,$3,$4,$5) RETURNING *;
|
||||
|
||||
-- name: DeleteLeadTarget :exec
|
||||
UPDATE leadtarget SET deleted = true WHERE id = $1;
|
||||
|
||||
-- name: UpdateLeadTarget :one
|
||||
UPDATE leadtarget SET target = $1,InviteLink = $2 WHERE id = $3 AND deleted=false RETURNING *;
|
||||
|
||||
-- name: GetLeadTarget :many
|
||||
SELECT * FROM leadtarget WHERE accountID = $1 AND quizID = $2 AND deleted=false;
|
||||
|
||||
-- name: CreateTgAccount :one
|
||||
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
||||
VALUES ($1, $2, $3, $4, $5) RETURNING id;
|
||||
|
||||
-- name: GetAllTgAccounts :many
|
||||
SELECT * FROM tgAccounts WHERE Deleted = false;
|
||||
|
||||
-- name: UpdateStatusTg :exec
|
||||
UPDATE tgAccounts SET Status = $1 WHERE id = $2;
|
||||
|
||||
-- name: SoftDeleteTgAccount :exec
|
||||
UPDATE tgAccounts SET Deleted = true WHERE id = $1;
|
||||
|
||||
-- name: SearchIDByAppIDanAppHash :one
|
||||
SELECT * FROM tgAccounts WHERE ApiID = $1 and ApiHash=$2 and Deleted = false;
|
10
dal/schema/000017_init.down.sql
Normal file
10
dal/schema/000017_init.down.sql
Normal file
@ -0,0 +1,10 @@
|
||||
ALTER TABLE account ADD column email varchar(50) NOT NULL default '';
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'leadtargettype') THEN
|
||||
DROP TYPE LeadTargetType;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DROP TABLE IF EXISTS leadtarget;
|
19
dal/schema/000017_init.up.sql
Normal file
19
dal/schema/000017_init.up.sql
Normal file
@ -0,0 +1,19 @@
|
||||
AlTER TABLE account DROP column email;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'leadtargettype') THEN
|
||||
CREATE TYPE LeadTargetType AS ENUM ('mail', 'telegram', 'whatsapp');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS leadtarget(
|
||||
ID BIGSERIAL UNIQUE NOT NULL PRIMARY KEY,
|
||||
AccountID varchar(30) NOT NULL,
|
||||
Type LeadTargetType NOT NULL,
|
||||
QuizID integer NOT NULL DEFAULT 0,
|
||||
Target text NOT NULL,
|
||||
InviteLink text NOT NULL DEFAULT '',
|
||||
Deleted boolean NOT NULL DEFAULT false,
|
||||
CreatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
10
dal/schema/000018_init.down.sql
Normal file
10
dal/schema/000018_init.down.sql
Normal file
@ -0,0 +1,10 @@
|
||||
DROP TABLE IF EXISTS tgAccounts;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tgAccountStatus') THEN
|
||||
DROP TYPE TgAccountStatus;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_apiid_apihash;
|
19
dal/schema/000018_init.up.sql
Normal file
19
dal/schema/000018_init.up.sql
Normal file
@ -0,0 +1,19 @@
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'tgAccountStatus') THEN
|
||||
CREATE TYPE TgAccountStatus AS ENUM ('active', 'inactive', 'ban');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tgAccounts (
|
||||
id bigserial primary key ,
|
||||
ApiID integer not null,
|
||||
ApiHash text not null ,
|
||||
PhoneNumber text not null ,
|
||||
Password text not null ,
|
||||
Status TgAccountStatus not null,
|
||||
Deleted bool not null default false,
|
||||
CreatedAt timestamp not null default current_timestamp
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_apiid_apihash ON tgAccounts (ApiID, ApiHash) WHERE Deleted = false;
|
11
dal/schema/000019_init.down.sql
Normal file
11
dal/schema/000019_init.down.sql
Normal file
@ -0,0 +1,11 @@
|
||||
ALTER TABLE account
|
||||
ALTER COLUMN user_id DROP NOT NULL,
|
||||
ALTER COLUMN created_at DROP NOT NULL,
|
||||
ALTER COLUMN deleted DROP NOT NULL;
|
||||
|
||||
ALTER TABLE privileges
|
||||
ALTER COLUMN privilegeID DROP NOT NULL,
|
||||
ALTER COLUMN account_id DROP NOT NULL,
|
||||
ALTER COLUMN privilege_name DROP NOT NULL,
|
||||
ALTER COLUMN amount DROP NOT NULL,
|
||||
ALTER COLUMN created_at DROP NOT NULL;
|
11
dal/schema/000019_init.up.sql
Normal file
11
dal/schema/000019_init.up.sql
Normal file
@ -0,0 +1,11 @@
|
||||
ALTER TABLE account
|
||||
ALTER COLUMN user_id SET NOT NULL,
|
||||
ALTER COLUMN created_at SET NOT NULL,
|
||||
ALTER COLUMN deleted SET NOT NULL;
|
||||
|
||||
ALTER TABLE privileges
|
||||
ALTER COLUMN privilegeID SET NOT NULL,
|
||||
ALTER COLUMN account_id SET NOT NULL,
|
||||
ALTER COLUMN privilege_name SET NOT NULL,
|
||||
ALTER COLUMN amount SET NOT NULL,
|
||||
ALTER COLUMN created_at SET NOT NULL;
|
@ -14,10 +14,9 @@ import (
|
||||
|
||||
type Account struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Email sql.NullString `db:"email" json:"email"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
}
|
||||
|
||||
type Accountsamo struct {
|
||||
@ -81,6 +80,17 @@ type Field struct {
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Leadtarget struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Type interface{} `db:"type" json:"type"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
Target string `db:"target" json:"target"`
|
||||
Invitelink string `db:"invitelink" json:"invitelink"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Pipeline struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
@ -93,11 +103,11 @@ type Pipeline struct {
|
||||
|
||||
type Privilege struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
AccountID uuid.UUID `db:"account_id" json:"account_id"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
@ -183,6 +193,17 @@ type Tag struct {
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Tgaccount struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Apiid int32 `db:"apiid" json:"apiid"`
|
||||
Apihash string `db:"apihash" json:"apihash"`
|
||||
Phonenumber string `db:"phonenumber" json:"phonenumber"`
|
||||
Password string `db:"password" json:"password"`
|
||||
Status interface{} `db:"status" json:"status"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat time.Time `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||
|
@ -25,22 +25,15 @@ type AccountPaginationParams struct {
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
type AccountPaginationRow struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
}
|
||||
|
||||
func (q *Queries) AccountPagination(ctx context.Context, arg AccountPaginationParams) ([]AccountPaginationRow, error) {
|
||||
func (q *Queries) AccountPagination(ctx context.Context, arg AccountPaginationParams) ([]Account, error) {
|
||||
rows, err := q.db.QueryContext(ctx, accountPagination, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []AccountPaginationRow
|
||||
var items []Account
|
||||
for rows.Next() {
|
||||
var i AccountPaginationRow
|
||||
var i Account
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
@ -180,9 +173,9 @@ WHERE privilege_name = $2
|
||||
`
|
||||
|
||||
type CheckAndAddDefaultParams struct {
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount_2 sql.NullInt32 `db:"amount_2" json:"amount_2"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount_2 int32 `db:"amount_2" json:"amount_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckAndAddDefault(ctx context.Context, arg CheckAndAddDefaultParams) error {
|
||||
@ -658,22 +651,20 @@ func (q *Queries) CopyQuizQuestions(ctx context.Context, arg CopyQuizQuestionsPa
|
||||
}
|
||||
|
||||
const createAccount = `-- name: CreateAccount :one
|
||||
INSERT INTO account (id, user_id, email, created_at, deleted) VALUES ($1, $2, $3, $4, $5) RETURNING id, user_id, email, created_at, deleted
|
||||
INSERT INTO account (id, user_id, created_at, deleted) VALUES ($1, $2, $3, $4) RETURNING id, user_id, created_at, deleted
|
||||
`
|
||||
|
||||
type CreateAccountParams struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Email sql.NullString `db:"email" json:"email"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAccount,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Email,
|
||||
arg.CreatedAt,
|
||||
arg.Deleted,
|
||||
)
|
||||
@ -681,7 +672,6 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.Deleted,
|
||||
)
|
||||
@ -716,6 +706,66 @@ func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountPara
|
||||
return err
|
||||
}
|
||||
|
||||
const createLeadTarget = `-- name: CreateLeadTarget :one
|
||||
INSERT INTO leadtarget (accountID,type,quizID,target,InviteLink) VALUES ($1,$2,$3,$4,$5) RETURNING id, accountid, type, quizid, target, invitelink, deleted, createdat
|
||||
`
|
||||
|
||||
type CreateLeadTargetParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Type interface{} `db:"type" json:"type"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
Target string `db:"target" json:"target"`
|
||||
Invitelink string `db:"invitelink" json:"invitelink"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateLeadTarget(ctx context.Context, arg CreateLeadTargetParams) (Leadtarget, error) {
|
||||
row := q.db.QueryRowContext(ctx, createLeadTarget,
|
||||
arg.Accountid,
|
||||
arg.Type,
|
||||
arg.Quizid,
|
||||
arg.Target,
|
||||
arg.Invitelink,
|
||||
)
|
||||
var i Leadtarget
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Accountid,
|
||||
&i.Type,
|
||||
&i.Quizid,
|
||||
&i.Target,
|
||||
&i.Invitelink,
|
||||
&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
|
||||
`
|
||||
|
||||
type CreateTgAccountParams struct {
|
||||
Apiid int32 `db:"apiid" json:"apiid"`
|
||||
Apihash string `db:"apihash" json:"apihash"`
|
||||
Phonenumber string `db:"phonenumber" json:"phonenumber"`
|
||||
Password string `db:"password" json:"password"`
|
||||
Status interface{} `db:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTgAccount(ctx context.Context, arg CreateTgAccountParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, createTgAccount,
|
||||
arg.Apiid,
|
||||
arg.Apihash,
|
||||
arg.Phonenumber,
|
||||
arg.Password,
|
||||
arg.Status,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createWebHook = `-- name: CreateWebHook :exec
|
||||
INSERT INTO tokens (AccountID, RefreshToken, AccessToken, AuthCode, Expiration, CreatedAt)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
@ -749,8 +799,8 @@ RETURNING p.id, p.privilegeID, p.account_id, p.privilege_name, p.amount, p.creat
|
||||
`
|
||||
|
||||
type DecrementManualParams struct {
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
}
|
||||
|
||||
func (q *Queries) DecrementManual(ctx context.Context, arg DecrementManualParams) (Privilege, error) {
|
||||
@ -785,6 +835,15 @@ func (q *Queries) DeleteFields(ctx context.Context, dollar_1 []int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteLeadTarget = `-- name: DeleteLeadTarget :exec
|
||||
UPDATE leadtarget SET deleted = true WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteLeadTarget(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteLeadTarget, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deletePipelines = `-- name: DeletePipelines :exec
|
||||
UPDATE pipelines SET Deleted = true WHERE ID = ANY($1::bigint[])
|
||||
`
|
||||
@ -798,7 +857,7 @@ const deletePrivilegeByAccID = `-- name: DeletePrivilegeByAccID :exec
|
||||
DELETE FROM privileges WHERE account_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePrivilegeByAccID(ctx context.Context, accountID uuid.NullUUID) error {
|
||||
func (q *Queries) DeletePrivilegeByAccID(ctx context.Context, accountID uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deletePrivilegeByAccID, accountID)
|
||||
return err
|
||||
}
|
||||
@ -1207,7 +1266,6 @@ const getAccAndPrivilegeByEmail = `-- name: GetAccAndPrivilegeByEmail :one
|
||||
SELECT
|
||||
a.id,
|
||||
a.user_id,
|
||||
a.email,
|
||||
a.created_at,
|
||||
COALESCE(p.ID,0),
|
||||
coalesce(p.privilegeid,''),
|
||||
@ -1222,22 +1280,20 @@ WHERE
|
||||
|
||||
type GetAccAndPrivilegeByEmailRow struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Email sql.NullString `db:"email" json:"email"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
ID_2 int32 `db:"id_2" json:"id_2"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt_2 sql.NullTime `db:"created_at_2" json:"created_at_2"`
|
||||
CreatedAt_2 time.Time `db:"created_at_2" json:"created_at_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAccAndPrivilegeByEmail(ctx context.Context, userID sql.NullString) (GetAccAndPrivilegeByEmailRow, error) {
|
||||
func (q *Queries) GetAccAndPrivilegeByEmail(ctx context.Context, userID string) (GetAccAndPrivilegeByEmailRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAccAndPrivilegeByEmail, userID)
|
||||
var i GetAccAndPrivilegeByEmailRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.ID_2,
|
||||
&i.Privilegeid,
|
||||
@ -1260,17 +1316,17 @@ WHERE a.user_id = $1
|
||||
|
||||
type GetAccountWithPrivilegesRow struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
PrivilegeID int32 `db:"privilege_id" json:"privilege_id"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
PrivilegeCreatedAt sql.NullTime `db:"privilege_created_at" json:"privilege_created_at"`
|
||||
PrivilegeCreatedAt time.Time `db:"privilege_created_at" json:"privilege_created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAccountWithPrivileges(ctx context.Context, userID sql.NullString) ([]GetAccountWithPrivilegesRow, error) {
|
||||
func (q *Queries) GetAccountWithPrivileges(ctx context.Context, userID string) ([]GetAccountWithPrivilegesRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAccountWithPrivileges, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1394,6 +1450,42 @@ func (q *Queries) GetAllCompanyUsers(ctx context.Context, amoid int32) ([]Usersa
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getAllTgAccounts = `-- name: GetAllTgAccounts :many
|
||||
SELECT id, apiid, apihash, phonenumber, password, status, deleted, createdat FROM tgAccounts WHERE Deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllTgAccounts(ctx context.Context) ([]Tgaccount, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAllTgAccounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tgaccount
|
||||
for rows.Next() {
|
||||
var i Tgaccount
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Apiid,
|
||||
&i.Apihash,
|
||||
&i.Phonenumber,
|
||||
&i.Password,
|
||||
&i.Status,
|
||||
&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 getAllTokens = `-- name: GetAllTokens :many
|
||||
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens
|
||||
`
|
||||
@ -1499,14 +1591,14 @@ WHERE p.amount = 0
|
||||
|
||||
type GetExpiredCountPrivilegeRow struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetExpiredCountPrivilege(ctx context.Context, privilegeid sql.NullString) ([]GetExpiredCountPrivilegeRow, error) {
|
||||
func (q *Queries) GetExpiredCountPrivilege(ctx context.Context, privilegeid string) ([]GetExpiredCountPrivilegeRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getExpiredCountPrivilege, privilegeid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1546,14 +1638,14 @@ WHERE p.created_at + p.amount * interval '1 day' < NOW()
|
||||
|
||||
type GetExpiredDayPrivilegeRow struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UserID string `db:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetExpiredDayPrivilege(ctx context.Context, privilegeid sql.NullString) ([]GetExpiredDayPrivilegeRow, error) {
|
||||
func (q *Queries) GetExpiredDayPrivilege(ctx context.Context, privilegeid string) ([]GetExpiredDayPrivilegeRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getExpiredDayPrivilege, privilegeid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1667,6 +1759,47 @@ func (q *Queries) GetFieldsWithPagination(ctx context.Context, arg GetFieldsWith
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getLeadTarget = `-- name: GetLeadTarget :many
|
||||
SELECT id, accountid, type, quizid, target, invitelink, deleted, createdat FROM leadtarget WHERE accountID = $1 AND quizID = $2 AND deleted=false
|
||||
`
|
||||
|
||||
type GetLeadTargetParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetLeadTarget(ctx context.Context, arg GetLeadTargetParams) ([]Leadtarget, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getLeadTarget, arg.Accountid, arg.Quizid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Leadtarget
|
||||
for rows.Next() {
|
||||
var i Leadtarget
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Accountid,
|
||||
&i.Type,
|
||||
&i.Quizid,
|
||||
&i.Target,
|
||||
&i.Invitelink,
|
||||
&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 getListCreatedQuizzes = `-- name: GetListCreatedQuizzes :many
|
||||
SELECT id
|
||||
FROM quiz
|
||||
@ -1788,13 +1921,13 @@ SELECT id,privilegeID,privilege_name,amount, created_at FROM privileges WHERE ac
|
||||
|
||||
type GetPrivilegesByAccountIDRow struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPrivilegesByAccountID(ctx context.Context, accountID uuid.NullUUID) ([]GetPrivilegesByAccountIDRow, error) {
|
||||
func (q *Queries) GetPrivilegesByAccountID(ctx context.Context, accountID uuid.UUID) ([]GetPrivilegesByAccountIDRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountID, accountID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1829,13 +1962,13 @@ SELECT p.id,p.privilegeID,p.privilege_name,p.amount, p.created_at FROM privilege
|
||||
|
||||
type GetPrivilegesByAccountIDWCRow struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPrivilegesByAccountIDWC(ctx context.Context, userID sql.NullString) ([]GetPrivilegesByAccountIDWCRow, error) {
|
||||
func (q *Queries) GetPrivilegesByAccountIDWC(ctx context.Context, userID string) ([]GetPrivilegesByAccountIDWCRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountIDWC, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1871,7 +2004,6 @@ SELECT
|
||||
p.amount,
|
||||
p.created_at,
|
||||
a.id,
|
||||
a.email,
|
||||
qz.config
|
||||
FROM
|
||||
privileges AS p
|
||||
@ -1882,12 +2014,11 @@ WHERE
|
||||
`
|
||||
|
||||
type GetPrivilegesQuizAccountRow struct {
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Email sql.NullString `db:"email" json:"email"`
|
||||
Config sql.NullString `db:"config" json:"config"`
|
||||
}
|
||||
|
||||
@ -1906,7 +2037,6 @@ func (q *Queries) GetPrivilegesQuizAccount(ctx context.Context, id int64) ([]Get
|
||||
&i.Amount,
|
||||
&i.CreatedAt,
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.Config,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@ -2955,11 +3085,11 @@ INSERT INTO privileges (privilegeID, account_id, privilege_name, amount, created
|
||||
`
|
||||
|
||||
type InsertPrivilegeParams struct {
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||||
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
AccountID uuid.UUID `db:"account_id" json:"account_id"`
|
||||
PrivilegeName string `db:"privilege_name" json:"privilege_name"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertPrivilege(ctx context.Context, arg InsertPrivilegeParams) error {
|
||||
@ -3348,6 +3478,31 @@ func (q *Queries) QuizCopyQid(ctx context.Context, arg QuizCopyQidParams) (QuizC
|
||||
return i, err
|
||||
}
|
||||
|
||||
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
|
||||
`
|
||||
|
||||
type SearchIDByAppIDanAppHashParams struct {
|
||||
Apiid int32 `db:"apiid" json:"apiid"`
|
||||
Apihash string `db:"apihash" json:"apihash"`
|
||||
}
|
||||
|
||||
func (q *Queries) SearchIDByAppIDanAppHash(ctx context.Context, arg SearchIDByAppIDanAppHashParams) (Tgaccount, error) {
|
||||
row := q.db.QueryRowContext(ctx, searchIDByAppIDanAppHash, arg.Apiid, arg.Apihash)
|
||||
var i Tgaccount
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Apiid,
|
||||
&i.Apihash,
|
||||
&i.Phonenumber,
|
||||
&i.Password,
|
||||
&i.Status,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setQuizSettings = `-- name: SetQuizSettings :one
|
||||
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule,TagsToAdd)
|
||||
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
||||
@ -3430,6 +3585,15 @@ func (q *Queries) SoftDeleteResultByID(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteTgAccount = `-- name: SoftDeleteTgAccount :exec
|
||||
UPDATE tgAccounts SET Deleted = true WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteTgAccount(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, softDeleteTgAccount, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const templateCopy = `-- name: TemplateCopy :one
|
||||
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)
|
||||
@ -3554,6 +3718,32 @@ func (q *Queries) UpdateFields(ctx context.Context, dollar_1 json.RawMessage) er
|
||||
return err
|
||||
}
|
||||
|
||||
const updateLeadTarget = `-- name: UpdateLeadTarget :one
|
||||
UPDATE leadtarget SET target = $1,InviteLink = $2 WHERE id = $3 AND deleted=false RETURNING id, accountid, type, quizid, target, invitelink, deleted, createdat
|
||||
`
|
||||
|
||||
type UpdateLeadTargetParams struct {
|
||||
Target string `db:"target" json:"target"`
|
||||
Invitelink string `db:"invitelink" json:"invitelink"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateLeadTarget(ctx context.Context, arg UpdateLeadTargetParams) (Leadtarget, error) {
|
||||
row := q.db.QueryRowContext(ctx, updateLeadTarget, arg.Target, arg.Invitelink, arg.ID)
|
||||
var i Leadtarget
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Accountid,
|
||||
&i.Type,
|
||||
&i.Quizid,
|
||||
&i.Target,
|
||||
&i.Invitelink,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updatePipelines = `-- name: UpdatePipelines :exec
|
||||
UPDATE pipelines AS p
|
||||
SET name = (update_data ->> 'Name')::varchar(512),
|
||||
@ -3573,10 +3763,10 @@ UPDATE privileges SET amount = $1, created_at = $2 WHERE account_id = $3 AND pri
|
||||
`
|
||||
|
||||
type UpdatePrivilegeParams struct {
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||||
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
AccountID uuid.UUID `db:"account_id" json:"account_id"`
|
||||
Privilegeid string `db:"privilegeid" json:"privilegeid"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePrivilege(ctx context.Context, arg UpdatePrivilegeParams) error {
|
||||
@ -3594,7 +3784,7 @@ UPDATE privileges SET amount = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
type UpdatePrivilegeAmountParams struct {
|
||||
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
ID int32 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
@ -3603,6 +3793,20 @@ func (q *Queries) UpdatePrivilegeAmount(ctx context.Context, arg UpdatePrivilege
|
||||
return err
|
||||
}
|
||||
|
||||
const updateStatusTg = `-- name: UpdateStatusTg :exec
|
||||
UPDATE tgAccounts SET Status = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
type UpdateStatusTgParams struct {
|
||||
Status interface{} `db:"status" json:"status"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStatusTg(ctx context.Context, arg UpdateStatusTgParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateStatusTg, arg.Status, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateSteps = `-- name: UpdateSteps :exec
|
||||
UPDATE steps AS s
|
||||
SET name = (update_data ->> 'Name')::varchar(512),
|
||||
|
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module penahub.gitlab.yandexcloud.net/backend/quiz/common.git
|
||||
go 1.21.4
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4
|
||||
github.com/gofiber/fiber/v2 v2.52.0
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0
|
||||
github.com/golang/protobuf v1.5.3
|
||||
@ -18,7 +19,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4 // indirect
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -4,6 +4,7 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
@ -61,6 +62,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
@ -282,7 +282,6 @@ type ExpiredPrivileges struct {
|
||||
type Account struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Deleted bool `json:"deleted"`
|
||||
Privileges map[string]ShortPrivilege `json:"privileges"`
|
||||
@ -308,3 +307,28 @@ type AnswerExport struct {
|
||||
}
|
||||
|
||||
type UTMSavingMap map[string]string
|
||||
|
||||
type LeadTarget struct {
|
||||
ID int64 `json:"id"`
|
||||
AccountID string `json:"accountID"`
|
||||
Type LeadTargetType `json:"type"`
|
||||
QuizID int32 `json:"quizID"`
|
||||
Target string `json:"target"`
|
||||
InviteLink string `json:"inviteLink"` // например указывается для типа телеграмма для созданного канала
|
||||
Deleted bool `json:"deleted"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type LeadTargetType string
|
||||
|
||||
const (
|
||||
LeadTargetEmail LeadTargetType = "mail"
|
||||
LeadTargetTg LeadTargetType = "telegram"
|
||||
LeadTargetWhatsapp LeadTargetType = "whatsapp"
|
||||
)
|
||||
|
||||
var ValidLeadTargetTypes = map[string]bool{
|
||||
"mail": true,
|
||||
"telegram": true,
|
||||
"whatsapp": true,
|
||||
}
|
||||
|
28
model/tg.go
Normal file
28
model/tg.go
Normal file
@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type TgAccount struct {
|
||||
ID int64
|
||||
ApiID int32
|
||||
ApiHash string
|
||||
PhoneNumber string
|
||||
Password string
|
||||
Status TgAccountStatus
|
||||
Deleted bool
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type TgAccountStatus string
|
||||
|
||||
const (
|
||||
ActiveTg TgAccountStatus = "active"
|
||||
InactiveTg TgAccountStatus = "inactive"
|
||||
BanTg TgAccountStatus = "ban"
|
||||
)
|
||||
|
||||
type TgRedisTask struct {
|
||||
Name string
|
||||
QuizID int32
|
||||
AccountID string
|
||||
}
|
@ -30,9 +30,7 @@ func NewAccountRepository(deps Deps) *AccountRepository {
|
||||
|
||||
// test +
|
||||
func (r *AccountRepository) GetAccountByID(ctx context.Context, userID string) (model.Account, error) {
|
||||
userIDSql := sql.NullString{String: userID, Valid: userID != ""}
|
||||
|
||||
accountRows, err := r.queries.GetAccountWithPrivileges(ctx, userIDSql)
|
||||
accountRows, err := r.queries.GetAccountWithPrivileges(ctx, userID)
|
||||
if err != nil {
|
||||
return model.Account{}, err
|
||||
}
|
||||
@ -43,9 +41,9 @@ func (r *AccountRepository) GetAccountByID(ctx context.Context, userID string) (
|
||||
for _, row := range accountRows {
|
||||
if account.ID == "" {
|
||||
account.ID = row.ID.String()
|
||||
account.UserID = row.UserID.String
|
||||
account.CreatedAt = row.CreatedAt.Time
|
||||
account.Deleted = row.Deleted.Bool
|
||||
account.UserID = row.UserID
|
||||
account.CreatedAt = row.CreatedAt
|
||||
account.Deleted = row.Deleted
|
||||
}
|
||||
|
||||
if row.PrivilegeID != 0 {
|
||||
@ -54,7 +52,7 @@ func (r *AccountRepository) GetAccountByID(ctx context.Context, userID string) (
|
||||
PrivilegeID: row.Privilegeid,
|
||||
PrivilegeName: row.PrivilegeName,
|
||||
Amount: uint64(row.Amount),
|
||||
CreatedAt: row.PrivilegeCreatedAt.Time,
|
||||
CreatedAt: row.PrivilegeCreatedAt,
|
||||
}
|
||||
privileges[privilege.PrivilegeID] = privilege
|
||||
}
|
||||
@ -70,9 +68,8 @@ func (r *AccountRepository) GetAccountByID(ctx context.Context, userID string) (
|
||||
|
||||
// test +
|
||||
func (r *AccountRepository) GetPrivilegesByAccountID(ctx context.Context, userID string) ([]model.ShortPrivilege, error) {
|
||||
userIDSql := sql.NullString{String: userID, Valid: userID != ""}
|
||||
|
||||
privilegeRows, err := r.queries.GetPrivilegesByAccountIDWC(ctx, userIDSql)
|
||||
privilegeRows, err := r.queries.GetPrivilegesByAccountIDWC(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -82,10 +79,10 @@ func (r *AccountRepository) GetPrivilegesByAccountID(ctx context.Context, userID
|
||||
for _, row := range privilegeRows {
|
||||
privilege := model.ShortPrivilege{
|
||||
ID: fmt.Sprintf("%d", row.ID),
|
||||
PrivilegeID: row.Privilegeid.String,
|
||||
PrivilegeName: row.PrivilegeName.String,
|
||||
Amount: uint64(row.Amount.Int32),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
PrivilegeID: row.Privilegeid,
|
||||
PrivilegeName: row.PrivilegeName,
|
||||
Amount: uint64(row.Amount),
|
||||
CreatedAt: row.CreatedAt,
|
||||
}
|
||||
privileges = append(privileges, privilege)
|
||||
}
|
||||
@ -98,10 +95,9 @@ func (r *AccountRepository) CreateAccount(ctx context.Context, data *model.Accou
|
||||
data.ID = uuid.NewString()
|
||||
row, err := r.queries.CreateAccount(ctx, sqlcgen.CreateAccountParams{
|
||||
ID: uuid.MustParse(data.ID),
|
||||
UserID: sql.NullString{String: data.UserID, Valid: data.UserID != ""},
|
||||
Email: sql.NullString{String: data.Email, Valid: data.Email != ""},
|
||||
CreatedAt: sql.NullTime{Time: data.CreatedAt, Valid: !data.CreatedAt.IsZero()},
|
||||
Deleted: sql.NullBool{Bool: data.Deleted, Valid: true},
|
||||
UserID: data.UserID,
|
||||
CreatedAt: data.CreatedAt,
|
||||
Deleted: data.Deleted,
|
||||
})
|
||||
if err != nil {
|
||||
return model.Account{}, fmt.Errorf("failed to create account: %w", err)
|
||||
@ -109,17 +105,16 @@ func (r *AccountRepository) CreateAccount(ctx context.Context, data *model.Accou
|
||||
|
||||
createdAccount := model.Account{
|
||||
ID: row.ID.String(),
|
||||
UserID: row.UserID.String,
|
||||
Email: row.Email.String,
|
||||
UserID: row.UserID,
|
||||
}
|
||||
|
||||
for _, privilege := range data.Privileges {
|
||||
err := r.queries.InsertPrivilege(ctx, sqlcgen.InsertPrivilegeParams{
|
||||
Privilegeid: sql.NullString{String: privilege.PrivilegeID, Valid: privilege.PrivilegeID != ""},
|
||||
AccountID: uuid.NullUUID{UUID: uuid.MustParse(data.ID), Valid: true},
|
||||
PrivilegeName: sql.NullString{String: privilege.PrivilegeName, Valid: privilege.PrivilegeName != ""},
|
||||
Amount: sql.NullInt32{Int32: int32(privilege.Amount), Valid: true},
|
||||
CreatedAt: sql.NullTime{Time: privilege.CreatedAt, Valid: !privilege.CreatedAt.IsZero()},
|
||||
Privilegeid: privilege.PrivilegeID,
|
||||
AccountID: uuid.MustParse(data.ID),
|
||||
PrivilegeName: privilege.PrivilegeName,
|
||||
Amount: int32(privilege.Amount),
|
||||
CreatedAt: privilege.CreatedAt,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -142,7 +137,7 @@ func (r *AccountRepository) DeleteAccount(ctx context.Context, accountID string)
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.queries.DeletePrivilegeByAccID(ctx, uuid.NullUUID{UUID: uuid.MustParse(accountID), Valid: true})
|
||||
err = r.queries.DeletePrivilegeByAccID(ctx, uuid.MustParse(accountID))
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@ -166,9 +161,9 @@ func (r *AccountRepository) GetAccounts(ctx context.Context, limit uint64, offse
|
||||
for _, row := range rows {
|
||||
account := model.Account{
|
||||
ID: row.ID.String(),
|
||||
UserID: row.UserID.String,
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
Deleted: row.Deleted.Bool,
|
||||
UserID: row.UserID,
|
||||
CreatedAt: row.CreatedAt,
|
||||
Deleted: row.Deleted,
|
||||
}
|
||||
|
||||
accounts = append(accounts, account)
|
||||
@ -180,10 +175,10 @@ func (r *AccountRepository) GetAccounts(ctx context.Context, limit uint64, offse
|
||||
// test +
|
||||
func (r *AccountRepository) UpdatePrivilege(ctx context.Context, privilege *model.ShortPrivilege, accountID string) error {
|
||||
err := r.queries.UpdatePrivilege(ctx, sqlcgen.UpdatePrivilegeParams{
|
||||
Amount: sql.NullInt32{Int32: int32(privilege.Amount), Valid: true},
|
||||
CreatedAt: sql.NullTime{Time: privilege.CreatedAt, Valid: !privilege.CreatedAt.IsZero()},
|
||||
AccountID: uuid.NullUUID{UUID: uuid.MustParse(accountID), Valid: true},
|
||||
Privilegeid: sql.NullString{String: privilege.PrivilegeID, Valid: privilege.PrivilegeID != ""},
|
||||
Amount: int32(privilege.Amount),
|
||||
CreatedAt: privilege.CreatedAt,
|
||||
AccountID: uuid.MustParse(accountID),
|
||||
Privilegeid: privilege.PrivilegeID,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -196,11 +191,11 @@ func (r *AccountRepository) UpdatePrivilege(ctx context.Context, privilege *mode
|
||||
// test +
|
||||
func (r *AccountRepository) InsertPrivilege(ctx context.Context, privilege *model.ShortPrivilege, accountID string) error {
|
||||
err := r.queries.InsertPrivilege(ctx, sqlcgen.InsertPrivilegeParams{
|
||||
Amount: sql.NullInt32{Int32: int32(privilege.Amount), Valid: true},
|
||||
CreatedAt: sql.NullTime{Time: privilege.CreatedAt, Valid: !privilege.CreatedAt.IsZero()},
|
||||
AccountID: uuid.NullUUID{UUID: uuid.MustParse(accountID), Valid: true},
|
||||
Privilegeid: sql.NullString{String: privilege.PrivilegeID, Valid: privilege.PrivilegeID != ""},
|
||||
PrivilegeName: sql.NullString{String: privilege.PrivilegeName, Valid: privilege.PrivilegeName != ""},
|
||||
Amount: int32(privilege.Amount),
|
||||
CreatedAt: privilege.CreatedAt,
|
||||
AccountID: uuid.MustParse(accountID),
|
||||
Privilegeid: privilege.PrivilegeID,
|
||||
PrivilegeName: privilege.PrivilegeName,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -212,7 +207,7 @@ func (r *AccountRepository) InsertPrivilege(ctx context.Context, privilege *mode
|
||||
|
||||
// test +
|
||||
func (r *AccountRepository) GetExpired(ctx context.Context, privilegeID string) ([]model.ExpiredPrivileges, error) {
|
||||
rows, err := r.queries.GetExpiredDayPrivilege(ctx, sql.NullString{String: privilegeID, Valid: privilegeID != ""})
|
||||
rows, err := r.queries.GetExpiredDayPrivilege(ctx, privilegeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -222,13 +217,13 @@ func (r *AccountRepository) GetExpired(ctx context.Context, privilegeID string)
|
||||
for _, row := range rows {
|
||||
privilege := model.ShortPrivilege{
|
||||
ID: fmt.Sprintf("%d", row.ID),
|
||||
PrivilegeID: row.Privilegeid.String,
|
||||
PrivilegeName: row.PrivilegeName.String,
|
||||
Amount: uint64(row.Amount.Int32),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
PrivilegeID: row.Privilegeid,
|
||||
PrivilegeName: row.PrivilegeName,
|
||||
Amount: uint64(row.Amount),
|
||||
CreatedAt: row.CreatedAt,
|
||||
}
|
||||
expiredRecords = append(expiredRecords, model.ExpiredPrivileges{
|
||||
UserID: row.UserID.String,
|
||||
UserID: row.UserID,
|
||||
Privilege: privilege,
|
||||
})
|
||||
|
||||
@ -238,7 +233,7 @@ func (r *AccountRepository) GetExpired(ctx context.Context, privilegeID string)
|
||||
}
|
||||
|
||||
func (r *AccountRepository) GetExpiredCount(ctx context.Context, privilegeID string) ([]model.ExpiredPrivileges, error) {
|
||||
rows, err := r.queries.GetExpiredCountPrivilege(ctx, sql.NullString{String: privilegeID, Valid: privilegeID != ""})
|
||||
rows, err := r.queries.GetExpiredCountPrivilege(ctx, privilegeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -248,13 +243,13 @@ func (r *AccountRepository) GetExpiredCount(ctx context.Context, privilegeID str
|
||||
for _, row := range rows {
|
||||
privilege := model.ShortPrivilege{
|
||||
ID: fmt.Sprintf("%d", row.ID),
|
||||
PrivilegeID: row.Privilegeid.String,
|
||||
PrivilegeName: row.PrivilegeName.String,
|
||||
Amount: uint64(row.Amount.Int32),
|
||||
CreatedAt: row.CreatedAt.Time,
|
||||
PrivilegeID: row.Privilegeid,
|
||||
PrivilegeName: row.PrivilegeName,
|
||||
Amount: uint64(row.Amount),
|
||||
CreatedAt: row.CreatedAt,
|
||||
}
|
||||
expiredRecords = append(expiredRecords, model.ExpiredPrivileges{
|
||||
UserID: row.UserID.String,
|
||||
UserID: row.UserID,
|
||||
Privilege: privilege,
|
||||
})
|
||||
|
||||
@ -265,9 +260,9 @@ func (r *AccountRepository) GetExpiredCount(ctx context.Context, privilegeID str
|
||||
|
||||
func (r *AccountRepository) CheckAndAddDefault(ctx context.Context, amount uint64, privilegeID string, zeroAmount uint64) error {
|
||||
err := r.queries.CheckAndAddDefault(ctx, sqlcgen.CheckAndAddDefaultParams{
|
||||
Amount: sql.NullInt32{Int32: int32(amount), Valid: true},
|
||||
PrivilegeName: sql.NullString{String: privilegeID, Valid: privilegeID != ""},
|
||||
Amount_2: sql.NullInt32{Int32: int32(zeroAmount), Valid: true},
|
||||
Amount: int32(amount),
|
||||
PrivilegeName: privilegeID,
|
||||
Amount_2: int32(zeroAmount),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -295,7 +290,7 @@ func (r *AccountRepository) UpdatePrivilegeAmount(ctx context.Context, ID string
|
||||
}
|
||||
|
||||
err = r.queries.UpdatePrivilegeAmount(ctx, sqlcgen.UpdatePrivilegeAmountParams{
|
||||
Amount: sql.NullInt32{Int32: int32(newAmount), Valid: true},
|
||||
Amount: int32(newAmount),
|
||||
ID: int32(intID),
|
||||
})
|
||||
|
||||
@ -311,22 +306,21 @@ func (r *AccountRepository) GetAccAndPrivilegeByEmail(ctx context.Context, email
|
||||
var account model.Account
|
||||
var privileges []model.ShortPrivilege
|
||||
|
||||
row, err := r.queries.GetAccAndPrivilegeByEmail(ctx, sql.NullString{String: email, Valid: true})
|
||||
row, err := r.queries.GetAccAndPrivilegeByEmail(ctx, email)
|
||||
if err != nil {
|
||||
return account, privileges, err
|
||||
}
|
||||
|
||||
account.ID = row.ID.String()
|
||||
account.UserID = row.UserID.String
|
||||
account.Email = row.Email.String
|
||||
account.CreatedAt = row.CreatedAt.Time
|
||||
account.UserID = row.UserID
|
||||
account.CreatedAt = row.CreatedAt
|
||||
|
||||
if row.ID_2 != 0 {
|
||||
privilege := model.ShortPrivilege{
|
||||
ID: fmt.Sprint(row.ID_2),
|
||||
PrivilegeID: row.Privilegeid,
|
||||
Amount: uint64(row.Amount),
|
||||
CreatedAt: row.CreatedAt_2.Time,
|
||||
CreatedAt: row.CreatedAt_2,
|
||||
}
|
||||
privileges = append(privileges, privilege)
|
||||
}
|
||||
@ -352,8 +346,8 @@ func (r *AccountRepository) GetQidOwner(ctx context.Context, qId string) (string
|
||||
|
||||
func (r *AccountRepository) ManualDone(ctx context.Context, userID string) error {
|
||||
_, err := r.queries.DecrementManual(ctx, sqlcgen.DecrementManualParams{
|
||||
UserID: sql.NullString{String: userID, Valid: true},
|
||||
Privilegeid: sql.NullString{String: "quizManual", Valid: true},
|
||||
UserID: userID,
|
||||
Privilegeid: "quizManual",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -365,3 +359,100 @@ func (r *AccountRepository) ManualDone(ctx context.Context, userID string) error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) PostLeadTarget(ctx context.Context, req model.LeadTarget) (model.LeadTarget, error) {
|
||||
row, err := r.queries.CreateLeadTarget(ctx, sqlcgen.CreateLeadTargetParams{
|
||||
Accountid: req.AccountID,
|
||||
Type: req.Type,
|
||||
Quizid: req.QuizID,
|
||||
Target: req.Target,
|
||||
Invitelink: req.InviteLink,
|
||||
})
|
||||
if err != nil {
|
||||
return model.LeadTarget{}, err
|
||||
}
|
||||
|
||||
var targetType model.LeadTargetType
|
||||
v := string(row.Type.([]byte))
|
||||
targetType = model.LeadTargetType(v)
|
||||
|
||||
return model.LeadTarget{
|
||||
ID: row.ID,
|
||||
AccountID: row.Accountid,
|
||||
Type: targetType,
|
||||
QuizID: row.Quizid,
|
||||
Target: row.Target,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
InviteLink: row.Invitelink,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) DeleteLeadTarget(ctx context.Context, id int64) error {
|
||||
err := r.queries.DeleteLeadTarget(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) GetLeadTarget(ctx context.Context, accountID string, quizID int32) ([]model.LeadTarget, error) {
|
||||
rows, err := r.queries.GetLeadTarget(ctx, sqlcgen.GetLeadTargetParams{
|
||||
Accountid: accountID,
|
||||
Quizid: quizID,
|
||||
})
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return []model.LeadTarget{}, pj_errors.ErrNotFound
|
||||
}
|
||||
return []model.LeadTarget{}, err
|
||||
}
|
||||
var leadTargets []model.LeadTarget
|
||||
for _, row := range rows {
|
||||
var targetType model.LeadTargetType
|
||||
v := string(row.Type.([]byte))
|
||||
targetType = model.LeadTargetType(v)
|
||||
|
||||
leadTargets = append(leadTargets, model.LeadTarget{
|
||||
ID: row.ID,
|
||||
AccountID: row.Accountid,
|
||||
Type: targetType,
|
||||
QuizID: row.Quizid,
|
||||
Target: row.Target,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
InviteLink: row.Invitelink,
|
||||
})
|
||||
}
|
||||
|
||||
return leadTargets, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) UpdateLeadTarget(ctx context.Context, req model.LeadTarget) (model.LeadTarget, error) {
|
||||
row, err := r.queries.UpdateLeadTarget(ctx, sqlcgen.UpdateLeadTargetParams{
|
||||
Invitelink: req.InviteLink,
|
||||
Target: req.Target,
|
||||
ID: req.ID,
|
||||
})
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return model.LeadTarget{}, pj_errors.ErrNotFound
|
||||
}
|
||||
return model.LeadTarget{}, err
|
||||
}
|
||||
|
||||
var targetType model.LeadTargetType
|
||||
v := string(row.Type.([]byte))
|
||||
targetType = model.LeadTargetType(v)
|
||||
|
||||
return model.LeadTarget{
|
||||
ID: row.ID,
|
||||
AccountID: row.Accountid,
|
||||
Type: targetType,
|
||||
QuizID: row.Quizid,
|
||||
Target: row.Target,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
InviteLink: row.Invitelink,
|
||||
}, nil
|
||||
}
|
||||
|
111
repository/tg/tg.go
Normal file
111
repository/tg/tg.go
Normal file
@ -0,0 +1,111 @@
|
||||
package tg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
type TgRepo struct {
|
||||
queries *sqlcgen.Queries
|
||||
pool *sql.DB
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Queries *sqlcgen.Queries
|
||||
Pool *sql.DB
|
||||
}
|
||||
|
||||
func NewTgRepo(deps Deps) *TgRepo {
|
||||
return &TgRepo{
|
||||
queries: deps.Queries,
|
||||
pool: deps.Pool,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TgRepo) CreateTgAccount(ctx context.Context, data model.TgAccount) (int64, error) {
|
||||
id, err := r.queries.CreateTgAccount(ctx, sqlcgen.CreateTgAccountParams{
|
||||
Apiid: data.ApiID,
|
||||
Apihash: data.ApiHash,
|
||||
Phonenumber: data.PhoneNumber,
|
||||
Status: data.Status,
|
||||
Password: data.Password,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return id, err
|
||||
}
|
||||
|
||||
func (r *TgRepo) GetAllTgAccounts(ctx context.Context) ([]model.TgAccount, error) {
|
||||
rows, err := r.queries.GetAllTgAccounts(ctx)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var result []model.TgAccount
|
||||
for _, row := range rows {
|
||||
var status model.TgAccountStatus
|
||||
s := string(row.Status.([]byte))
|
||||
status = model.TgAccountStatus(s)
|
||||
result = append(result, model.TgAccount{
|
||||
ID: row.ID,
|
||||
ApiID: row.Apiid,
|
||||
ApiHash: row.Apihash,
|
||||
PhoneNumber: row.Phonenumber,
|
||||
Status: status,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
Password: row.Password,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *TgRepo) UpdateStatusTg(ctx context.Context, id int64, status model.TgAccountStatus) error {
|
||||
err := r.queries.UpdateStatusTg(ctx, sqlcgen.UpdateStatusTgParams{
|
||||
Status: status,
|
||||
ID: id,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *TgRepo) SoftDeleteTgAccount(ctx context.Context, id int64) error {
|
||||
err := r.queries.SoftDeleteTgAccount(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *TgRepo) SearchIDByAppIDanAppHash(ctx context.Context, appID int32, appHash string) (*model.TgAccount, error) {
|
||||
row, err := r.queries.SearchIDByAppIDanAppHash(ctx, sqlcgen.SearchIDByAppIDanAppHashParams{
|
||||
Apiid: appID,
|
||||
Apihash: appHash,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var status model.TgAccountStatus
|
||||
s := string(row.Status.([]byte))
|
||||
status = model.TgAccountStatus(s)
|
||||
|
||||
return &model.TgAccount{
|
||||
ID: row.ID,
|
||||
ApiID: row.Apiid,
|
||||
ApiHash: row.Apihash,
|
||||
PhoneNumber: row.Phonenumber,
|
||||
Status: status,
|
||||
Deleted: row.Deleted,
|
||||
CreatedAt: row.Createdat,
|
||||
Password: row.Password,
|
||||
}, nil
|
||||
}
|
@ -34,6 +34,12 @@ 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"
|
||||
- "./dal/schema/000018_init.up.sql"
|
||||
- "./dal/schema/000018_init.down.sql"
|
||||
- "./dal/schema/000019_init.up.sql"
|
||||
- "./dal/schema/000019_init.down.sql"
|
||||
engine: "postgresql"
|
||||
emit_json_tags: true
|
||||
emit_db_tags: true
|
||||
|
Loading…
Reference in New Issue
Block a user