From cc4d4eacad6b6a92ebb3380715dcaee3bcc5fd41 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 4 Feb 2023 00:02:34 +0800 Subject: refactor(db): migrate methods off `user.go` (#7331) --- internal/db/orgs.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'internal/db/orgs.go') 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 { -- cgit v1.2.3