diff options
author | Joe Chen <jc@unknwon.io> | 2023-02-04 00:02:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-04 00:02:34 +0800 |
commit | cc4d4eacad6b6a92ebb3380715dcaee3bcc5fd41 (patch) | |
tree | 36889c562b8560c2065199ca4b1b01ccfad179c9 /internal/db/orgs.go | |
parent | c53a1998c589a544b25d53f6e6fdf0f24a4df25b (diff) |
refactor(db): migrate methods off `user.go` (#7331)
Diffstat (limited to 'internal/db/orgs.go')
-rw-r--r-- | internal/db/orgs.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/internal/db/orgs.go b/internal/db/orgs.go index e7e8dd16..db1078ba 100644 --- a/internal/db/orgs.go +++ b/internal/db/orgs.go @@ -19,6 +19,12 @@ import ( type OrgsStore interface { // List returns a list of organizations filtered by options. List(ctx context.Context, opts ListOrgsOptions) ([]*Organization, error) + // SearchByName returns a list of organizations whose username or full name + // matches the given keyword case-insensitively. Results are paginated by given + // page and page size, and sorted by the given order (e.g. "id DESC"). A total + // count of all results is also returned. If the order is not given, it's up to + // the database to decide. + SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) } var Orgs OrgsStore @@ -69,6 +75,10 @@ func (db *orgs) List(ctx context.Context, opts ListOrgsOptions) ([]*Organization return orgs, tx.Find(&orgs).Error } +func (db *orgs) SearchByName(ctx context.Context, keyword string, page, pageSize int, orderBy string) ([]*Organization, int64, error) { + return searchUserByName(ctx, db.DB, UserTypeOrganization, keyword, page, pageSize, orderBy) +} + type Organization = User func (o *Organization) TableName() string { |