Skip to content

Commit

Permalink
add TenantID to UserFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Nov 19, 2023
1 parent 51e8512 commit e0a4a51
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ type UserService interface {
// UserFilter is a filter passed to FindUsers()
type UserFilter struct {
// Filtering fields.
ID *string
Email *string
APIKey *string
Email *string
TenantID *string

// Restrict to subset of results.
Offset int
Expand Down
5 changes: 4 additions & 1 deletion db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type User struct {
Email string
AvatarURL string
Role string
TenantID string
LastLoginAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
Expand Down Expand Up @@ -119,12 +120,14 @@ func findUserByID(ctx echo.Context, id string) (User, error) {
// findUsers returns a list of users. Also returns a count of
// total matching users which may differ if filter.Limit is set.
func findUsers(ctx echo.Context, filter app.UserFilter) ([]User, int, error) {
// TODO: implement (or remove) other filter parameters
var users []User
q := Tx(ctx)
if filter.Email != nil {
q = q.Where("email = ?", filter.Email)
}
if filter.TenantID != nil {
q = q.Where("tenant_id = ?", filter.TenantID)
}
result := q.Find(&users)
return users, len(users), result.Error
}
Expand Down

0 comments on commit e0a4a51

Please sign in to comment.