2024-06-27 19:30:57 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
2024-06-27 19:44:40 +00:00
|
|
|
Password: data.Password,
|
2024-06-27 19:30:57 +00:00
|
|
|
})
|
|
|
|
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 {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var result []model.TgAccount
|
|
|
|
for _, row := range rows {
|
|
|
|
result = append(result, model.TgAccount{
|
|
|
|
ID: row.ID,
|
|
|
|
ApiID: row.Apiid,
|
|
|
|
ApiHash: row.Apihash,
|
|
|
|
PhoneNumber: row.Phonenumber,
|
|
|
|
Status: row.Status.(model.TgAccountStatus),
|
|
|
|
Deleted: row.Deleted,
|
|
|
|
CreatedAt: row.Createdat,
|
2024-06-27 19:44:40 +00:00
|
|
|
Password: row.Password,
|
2024-06-27 19:30:57 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|