summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/db/bundb/user.go14
-rw-r--r--internal/db/bundb/user_test.go6
-rw-r--r--internal/db/user.go2
3 files changed, 22 insertions, 0 deletions
diff --git a/internal/db/bundb/user.go b/internal/db/bundb/user.go
index 68fdb0652..b5dae1573 100644
--- a/internal/db/bundb/user.go
+++ b/internal/db/bundb/user.go
@@ -122,6 +122,20 @@ func (u *userDB) GetUserByConfirmationToken(ctx context.Context, confirmationTok
}, confirmationToken)
}
+func (u *userDB) GetAllUsers(ctx context.Context) ([]*gtsmodel.User, db.Error) {
+ var users []*gtsmodel.User
+ q := u.conn.
+ NewSelect().
+ Model(&users).
+ Relation("Account")
+
+ if err := q.Scan(ctx); err != nil {
+ return nil, u.conn.ProcessError(err)
+ }
+
+ return users, nil
+}
+
func (u *userDB) PutUser(ctx context.Context, user *gtsmodel.User) db.Error {
return u.state.Caches.GTS.User().Store(user, func() error {
_, err := u.conn.
diff --git a/internal/db/bundb/user_test.go b/internal/db/bundb/user_test.go
index f2ce434c1..870a1af91 100644
--- a/internal/db/bundb/user_test.go
+++ b/internal/db/bundb/user_test.go
@@ -29,6 +29,12 @@ type UserTestSuite struct {
BunDBStandardTestSuite
}
+func (suite *UserTestSuite) TestGetAllUsers() {
+ users, err := suite.db.GetAllUsers(context.Background())
+ suite.NoError(err)
+ suite.Len(users, len(suite.testUsers))
+}
+
func (suite *UserTestSuite) TestGetUser() {
user, err := suite.db.GetUserByID(context.Background(), suite.testUsers["local_account_1"].ID)
suite.NoError(err)
diff --git a/internal/db/user.go b/internal/db/user.go
index e93ac4529..15165d0be 100644
--- a/internal/db/user.go
+++ b/internal/db/user.go
@@ -25,6 +25,8 @@ import (
// User contains functions related to user getting/setting/creation.
type User interface {
+ // GetAllUsers returns all local user accounts, or an error if something goes wrong.
+ GetAllUsers(ctx context.Context) ([]*gtsmodel.User, Error)
// GetUserByID returns one user with the given ID, or an error if something goes wrong.
GetUserByID(ctx context.Context, id string) (*gtsmodel.User, Error)
// GetUserByAccountID returns one user by its account ID, or an error if something goes wrong.