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/result"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/statistics"
|
"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/common.git/repository/workers"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +25,6 @@ var errNextDeclined = errors.New("next is declined")
|
|||||||
|
|
||||||
type DAL struct {
|
type DAL struct {
|
||||||
conn *sql.DB
|
conn *sql.DB
|
||||||
authClient *auth.AuthClient
|
|
||||||
queries *sqlcgen.Queries
|
queries *sqlcgen.Queries
|
||||||
AccountRepo *account.AccountRepository
|
AccountRepo *account.AccountRepository
|
||||||
AnswerRepo *answer.AnswerRepository
|
AnswerRepo *answer.AnswerRepository
|
||||||
@ -37,7 +35,7 @@ type DAL struct {
|
|||||||
StatisticsRepo *statistics.StatisticsRepository
|
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)
|
pool, err := sql.Open("postgres", cred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -54,7 +52,6 @@ func New(ctx context.Context, cred string, authClient *auth.AuthClient, minioCli
|
|||||||
|
|
||||||
accountRepo := account.NewAccountRepository(account.Deps{
|
accountRepo := account.NewAccountRepository(account.Deps{
|
||||||
Queries: queries,
|
Queries: queries,
|
||||||
AuthClient: authClient,
|
|
||||||
Pool: pool,
|
Pool: pool,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -99,7 +96,6 @@ func New(ctx context.Context, cred string, authClient *auth.AuthClient, minioCli
|
|||||||
|
|
||||||
return &DAL{
|
return &DAL{
|
||||||
conn: pool,
|
conn: pool,
|
||||||
authClient: authClient,
|
|
||||||
queries: queries,
|
queries: queries,
|
||||||
AccountRepo: accountRepo,
|
AccountRepo: accountRepo,
|
||||||
AnswerRepo: answerRepo,
|
AnswerRepo: answerRepo,
|
||||||
|
@ -7,26 +7,22 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
|
"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/model"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
Queries *sqlcgen.Queries
|
Queries *sqlcgen.Queries
|
||||||
AuthClient *auth.AuthClient
|
|
||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountRepository struct {
|
type AccountRepository struct {
|
||||||
queries *sqlcgen.Queries
|
queries *sqlcgen.Queries
|
||||||
authClient *auth.AuthClient
|
|
||||||
pool *sql.DB
|
pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccountRepository(deps Deps) *AccountRepository {
|
func NewAccountRepository(deps Deps) *AccountRepository {
|
||||||
return &AccountRepository{
|
return &AccountRepository{
|
||||||
queries: deps.Queries,
|
queries: deps.Queries,
|
||||||
authClient: deps.AuthClient,
|
|
||||||
pool: deps.Pool,
|
pool: deps.Pool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,17 +94,12 @@ func (r *AccountRepository) GetPrivilegesByAccountID(ctx context.Context, userID
|
|||||||
|
|
||||||
// todo test
|
// todo test
|
||||||
func (r *AccountRepository) CreateAccount(ctx context.Context, data *model.Account) error {
|
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()
|
data.ID = uuid.NewString()
|
||||||
|
|
||||||
err = r.queries.CreateAccount(ctx, sqlcgen.CreateAccountParams{
|
err := r.queries.CreateAccount(ctx, sqlcgen.CreateAccountParams{
|
||||||
ID: uuid.MustParse(data.ID),
|
ID: uuid.MustParse(data.ID),
|
||||||
UserID: sql.NullString{String: data.UserID, Valid: data.UserID != ""},
|
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()},
|
CreatedAt: sql.NullTime{Time: data.CreatedAt, Valid: !data.CreatedAt.IsZero()},
|
||||||
Deleted: sql.NullBool{Bool: data.Deleted, Valid: true},
|
Deleted: sql.NullBool{Bool: data.Deleted, Valid: true},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user