aboutsummaryrefslogtreecommitdiff
path: root/pkg/database
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database')
-rw-r--r--pkg/database/sql/user.go6
-rw-r--r--pkg/database/sql/user_test.go12
2 files changed, 9 insertions, 9 deletions
diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go
index a02b67b..a0884f4 100644
--- a/pkg/database/sql/user.go
+++ b/pkg/database/sql/user.go
@@ -137,7 +137,7 @@ func (self *UserRepository) GetPassword(ctx context.Context, id uint) ([]byte, e
return userPassword.Password, nil
}
-func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) error {
+func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateUser) (uint, error) {
user := &User{
Username: createUser.Username,
Name: createUser.Name,
@@ -148,10 +148,10 @@ func (self *UserRepository) Create(ctx context.Context, createUser *user.CreateU
WithContext(ctx).
Create(user)
if result.Error != nil {
- return result.Error
+ return 0, result.Error
}
- return nil
+ return user.Model.ID, nil
}
func (self *UserRepository) Update(ctx context.Context, id uint, update *user.UpdateUser) error {
diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index 473ce03..f0d89ad 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -48,7 +48,7 @@ func TestCreate(t *testing.T) {
repository := NewUserRepository(db)
- err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := repository.Create(context.Background(), &user.CreateUser{
Username: "new_username",
Name: "new_name",
})
@@ -56,12 +56,12 @@ func TestCreate(t *testing.T) {
t.Fatalf("Error creating: %s", err.Error())
}
- got, err := repository.Get(context.Background(), 1)
+ got, err := repository.Get(context.Background(), id)
if err != nil {
t.Fatalf("Error getting: %s", err.Error())
}
want := &user.User{
- ID: 1,
+ ID: id,
Username: "new_username",
Name: "new_name",
}
@@ -78,7 +78,7 @@ func TestUpdate(t *testing.T) {
repository := NewUserRepository(db)
- err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := repository.Create(context.Background(), &user.CreateUser{
Username: "username",
Name: "name",
})
@@ -86,7 +86,7 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error creating user: %s", err.Error())
}
- err = repository.Update(context.Background(), 1, &user.UpdateUser{
+ err = repository.Update(context.Background(), id, &user.UpdateUser{
Username: "new_username",
Name: "new_name",
})
@@ -99,7 +99,7 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error getting user: %s", err.Error())
}
want := &user.User{
- ID: 1,
+ ID: id,
Username: "new_username",
Name: "new_name",
}