remove auth client for avoid cycle import
This commit is contained in:
parent
6ce70d76fe
commit
5c23a0151e
@ -18,7 +18,6 @@ import (
|
||||
"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/workers"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -26,7 +25,6 @@ var errNextDeclined = errors.New("next is declined")
|
||||
|
||||
type DAL struct {
|
||||
conn *sql.DB
|
||||
authClient *auth.AuthClient
|
||||
queries *sqlcgen.Queries
|
||||
AccountRepo *account.AccountRepository
|
||||
AnswerRepo *answer.AnswerRepository
|
||||
@ -37,7 +35,7 @@ type DAL struct {
|
||||
StatisticsRepo *statistics.StatisticsRepository
|
||||
}
|
||||
|
||||
func New(ctx context.Context, cred string, authClient *auth.AuthClient, minioClient *minio.Client) (*DAL, error) {
|
||||
func New(ctx context.Context, cred string, minioClient *minio.Client) (*DAL, error) {
|
||||
pool, err := sql.Open("postgres", cred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -54,7 +52,6 @@ func New(ctx context.Context, cred string, authClient *auth.AuthClient, minioCli
|
||||
|
||||
accountRepo := account.NewAccountRepository(account.Deps{
|
||||
Queries: queries,
|
||||
AuthClient: authClient,
|
||||
Pool: pool,
|
||||
})
|
||||
|
||||
@ -99,7 +96,6 @@ func New(ctx context.Context, cred string, authClient *auth.AuthClient, minioCli
|
||||
|
||||
return &DAL{
|
||||
conn: pool,
|
||||
authClient: authClient,
|
||||
queries: queries,
|
||||
AccountRepo: accountRepo,
|
||||
AnswerRepo: answerRepo,
|
||||
|
@ -7,26 +7,22 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"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/core.git/clients/auth"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Queries *sqlcgen.Queries
|
||||
AuthClient *auth.AuthClient
|
||||
Pool *sql.DB
|
||||
}
|
||||
|
||||
type AccountRepository struct {
|
||||
queries *sqlcgen.Queries
|
||||
authClient *auth.AuthClient
|
||||
pool *sql.DB
|
||||
}
|
||||
|
||||
func NewAccountRepository(deps Deps) *AccountRepository {
|
||||
return &AccountRepository{
|
||||
queries: deps.Queries,
|
||||
authClient: deps.AuthClient,
|
||||
pool: deps.Pool,
|
||||
}
|
||||
}
|
||||
@ -98,17 +94,12 @@ func (r *AccountRepository) GetPrivilegesByAccountID(ctx context.Context, userID
|
||||
|
||||
// todo test
|
||||
func (r *AccountRepository) CreateAccount(ctx context.Context, data *model.Account) error {
|
||||
email, err := r.authClient.GetUserEmail(data.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data.ID = uuid.NewString()
|
||||
|
||||
err = r.queries.CreateAccount(ctx, sqlcgen.CreateAccountParams{
|
||||
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: email, Valid: email != ""},
|
||||
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},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user