diff options
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 +} |