aboutsummaryrefslogtreecommitdiff
path: root/pkg/database
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database')
-rw-r--r--pkg/database/repository/user.go5
-rw-r--r--pkg/database/sql/user.go28
2 files changed, 26 insertions, 7 deletions
diff --git a/pkg/database/repository/user.go b/pkg/database/repository/user.go
index 3589007..5b2e386 100644
--- a/pkg/database/repository/user.go
+++ b/pkg/database/repository/user.go
@@ -14,7 +14,8 @@ type (
UpdateUser struct {
Username string
Name string
- Password string
+ IsAdmin bool
+ Path string
}
CreateUser struct {
@@ -31,6 +32,8 @@ type (
List(ctx context.Context) ([]*User, error)
Create(ctx context.Context, createUser *CreateUser) (uint, error)
Update(ctx context.Context, id uint, updateUser *UpdateUser) error
+ Delete(ctx context.Context, id uint) error
+ UpdatePassword(ctx context.Context, id uint, password []byte) error
Any(ctx context.Context) (bool, error)
}
)
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
+}