feat: add ability to create an account via the webui (#223)

* feat: add ability to create an account via the webui without the need for autobrrctl

* refactor redundant code block.

* fix: early return and 0 value
This commit is contained in:
stacksmash76 2022-04-10 18:26:14 +02:00 committed by GitHub
parent 982eddc269
commit 1a4f3cf55d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 337 additions and 109 deletions

View file

@ -15,6 +15,29 @@ func NewUserRepo(db *DB) domain.UserRepo {
return &UserRepo{db: db}
}
func (r *UserRepo) GetUserCount(ctx context.Context) (int, error) {
queryBuilder := r.db.squirrel.Select("count(*)").From("users")
query, args, err := queryBuilder.ToSql()
if err != nil {
log.Error().Stack().Err(err).Msg("user.store: error building query")
return 0, err
}
row := r.db.handler.QueryRowContext(ctx, query, args...)
if err := row.Err(); err != nil {
return 0, err
}
result := 0
if err := row.Scan(&result); err != nil {
log.Error().Err(err).Msg("could not query number of users")
return 0, err
}
return result, nil
}
func (r *UserRepo) FindByUsername(ctx context.Context, username string) (*domain.User, error) {
queryBuilder := r.db.squirrel.
@ -66,6 +89,7 @@ func (r *UserRepo) Store(ctx context.Context, user domain.User) error {
return err
}
func (r *UserRepo) Update(ctx context.Context, user domain.User) error {
var err error