diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-22 18:45:59 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-07-22 19:35:33 +0200 |
commit | 3b9d27649a31e5af3fb137ff5b3378e7b8f7b9ae (patch) | |
tree | 0f43f30d824b8b805e4a72b66a0ee1bee7397803 /pkg/database/sql | |
parent | 1e4613aa1113b373a8d841c28e222599237a33c5 (diff) | |
download | lens-3b9d27649a31e5af3fb137ff5b3378e7b8f7b9ae.tar.gz lens-3b9d27649a31e5af3fb137ff5b3378e7b8f7b9ae.tar.bz2 lens-3b9d27649a31e5af3fb137ff5b3378e7b8f7b9ae.zip |
feat: Add user management
As many things it is on crude state. The settings.go has become a big
mess, but I have achieve MVP, so from now one things shall improve as
I'll spent more time on refactoring.
Diffstat (limited to 'pkg/database/sql')
-rw-r--r-- | pkg/database/sql/user.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go index 15dbe72..6b1cf0f 100644 --- a/pkg/database/sql/user.go +++ b/pkg/database/sql/user.go @@ -27,6 +27,7 @@ type ( ) var _ repository.UserRepository = &UserRepository{} + var _ repository.AuthRepository = &UserRepository{} func NewUserRepository(db *gorm.DB) *UserRepository { @@ -141,6 +142,7 @@ func (self *UserRepository) Create(ctx context.Context, createUser *repository.C Username: createUser.Username, Name: createUser.Name, Path: createUser.Path, + IsAdmin: createUser.IsAdmin, Password: string(createUser.Password), } @@ -161,11 +163,14 @@ func (self *UserRepository) Update(ctx context.Context, id uint, update *reposit }, Username: update.Username, Name: update.Name, + IsAdmin: update.IsAdmin, + Path: update.Path, } result := self.db. WithContext(ctx). - Save(user) + Omit("password"). + Updates(user) if result.Error != nil { return result.Error } @@ -174,14 +179,15 @@ func (self *UserRepository) Update(ctx context.Context, id uint, update *reposit } func (self *UserRepository) Delete(ctx context.Context, id uint) error { - userID := struct { - ID uint - }{ - ID: id, + user := &User{ + Model: gorm.Model{ + ID: id, + }, } + result := self.db. WithContext(ctx). - Delete(userID) + Delete(user) if result.Error != nil { return result.Error } @@ -219,3 +225,13 @@ func (u *UserRepository) GetPathFromUserID(ctx context.Context, id uint) (string return userPath, nil } + +func (u *UserRepository) UpdatePassword(ctx context.Context, id uint, password []byte) error { + result := u.db. + WithContext(ctx). + Model(&User{}). + Where("id = ?", id). + Update("password", password) + + return result.Error +} |