add tg repo and some methods
This commit is contained in:
parent
0f877904d4
commit
dc9d354429
@ -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
|
||||
}
|
||||
|
||||
|
||||
21
model/tg.go
Normal file
21
model/tg.go
Normal file
@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type TgAccount struct {
|
||||
ID int64
|
||||
ApiID int32
|
||||
ApiHash string
|
||||
PhoneNumber string
|
||||
Status TgAccountStatus
|
||||
Deleted bool
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type TgAccountStatus string
|
||||
|
||||
const (
|
||||
ActiveTg TgAccountStatus = "active"
|
||||
InactiveTg TgAccountStatus = "inactive"
|
||||
BanTg TgAccountStatus = "ban"
|
||||
)
|
||||
59
repository/tg/tg.go
Normal file
59
repository/tg/tg.go
Normal file
@ -0,0 +1,59 @@
|
||||
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,
|
||||
})
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user