mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
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:
parent
982eddc269
commit
1a4f3cf55d
11 changed files with 337 additions and 109 deletions
|
@ -2,11 +2,14 @@ package user
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetUserCount(ctx context.Context) (int, error)
|
||||
FindByUsername(ctx context.Context, username string) (*domain.User, error)
|
||||
CreateUser(ctx context.Context, user domain.User) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
|
@ -19,6 +22,10 @@ func NewService(repo domain.UserRepo) Service {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *service) GetUserCount(ctx context.Context) (int, error) {
|
||||
return s.repo.GetUserCount(ctx)
|
||||
}
|
||||
|
||||
func (s *service) FindByUsername(ctx context.Context, username string) (*domain.User, error) {
|
||||
user, err := s.repo.FindByUsername(ctx, username)
|
||||
if err != nil {
|
||||
|
@ -27,3 +34,16 @@ func (s *service) FindByUsername(ctx context.Context, username string) (*domain.
|
|||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *service) CreateUser(ctx context.Context, newUser domain.User) error {
|
||||
userCount, err := s.repo.GetUserCount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if userCount > 0 {
|
||||
return errors.New("only 1 user account is supported at the moment")
|
||||
}
|
||||
|
||||
return s.repo.Store(ctx, newUser)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue