diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-29 23:05:23 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-29 23:06:44 +0200 |
commit | 024da3e546e98cbaeea5f7bc86af12b671996f41 (patch) | |
tree | 08b38491b7e726fb448cceaceb2ef536360b2223 /pkg/components/auth/controller.go | |
parent | 9ba53fea71728ce64342d0d59f4199876e4b6164 (diff) | |
download | lens-024da3e546e98cbaeea5f7bc86af12b671996f41.tar.gz lens-024da3e546e98cbaeea5f7bc86af12b671996f41.tar.bz2 lens-024da3e546e98cbaeea5f7bc86af12b671996f41.zip |
ref: Refactor how repository is define
To make things easier and reduce the number of package I'll move all
repository to one folder, starting with auth and user repository.
Also implements all testing on top of the repository interface with a im
memory implementation. This will later make mescling unit and
integration easier.
Diffstat (limited to 'pkg/components/auth/controller.go')
-rw-r--r-- | pkg/components/auth/controller.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/pkg/components/auth/controller.go b/pkg/components/auth/controller.go index a33d9b3..0b08fcc 100644 --- a/pkg/components/auth/controller.go +++ b/pkg/components/auth/controller.go @@ -6,35 +6,35 @@ import ( "golang.org/x/crypto/bcrypt" "git.sr.ht/~gabrielgio/img/pkg/components" - "git.sr.ht/~gabrielgio/img/pkg/components/user" + "git.sr.ht/~gabrielgio/img/pkg/database/repository" "git.sr.ht/~gabrielgio/img/pkg/ext" ) type Controller struct { - repository Repository - userRepository user.Repository + authRepository repository.AuthRepository + userRepository repository.UserRepository key []byte } func NewController( - repository Repository, - userRepository user.Repository, + authRepository repository.AuthRepository, + userRepository repository.UserRepository, key []byte, ) *Controller { return &Controller{ - repository: repository, + authRepository: authRepository, userRepository: userRepository, key: key, } } func (c *Controller) Login(ctx context.Context, username, password []byte) ([]byte, error) { - id, err := c.repository.GetIDByUsername(ctx, string(username)) + id, err := c.authRepository.GetIDByUsername(ctx, string(username)) if err != nil { return nil, err } - hashedPassword, err := c.repository.GetPassword(ctx, id) + hashedPassword, err := c.authRepository.GetPassword(ctx, id) if err != nil { return nil, err } @@ -67,7 +67,7 @@ func (c *Controller) InitialRegister(ctx context.Context, username, password []b return err } - _, err = c.userRepository.Create(ctx, &user.CreateUser{ + _, err = c.userRepository.Create(ctx, &repository.CreateUser{ Username: string(username), Password: hash, Path: string(path), |