diff options
author | Joe Chen <jc@unknwon.io> | 2023-02-08 13:55:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 13:55:54 +0800 |
commit | 8350daf505b837984397679f07ccc2324b4d2451 (patch) | |
tree | 19d3bd7b8dc8370a8973614a74537bddc5f618a6 /internal/db/orgs.go | |
parent | 133b9d90441008ee175e1f8e6369e06309e1392a (diff) |
refactor(db): merge relation stores into entity stores (#7341)
Diffstat (limited to 'internal/db/orgs.go')
-rw-r--r-- | internal/db/orgs.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/internal/db/orgs.go b/internal/db/orgs.go index db1078ba..753d8120 100644 --- a/internal/db/orgs.go +++ b/internal/db/orgs.go @@ -14,8 +14,6 @@ import ( ) // OrgsStore is the persistent interface for organizations. -// -// NOTE: All methods are sorted in alphabetical order. type OrgsStore interface { // List returns a list of organizations filtered by options. List(ctx context.Context, opts ListOrgsOptions) ([]*Organization, error) @@ -25,6 +23,9 @@ type OrgsStore interface { // 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) + + // CountByUser returns the number of organizations the user is a member of. + CountByUser(ctx context.Context, userID int64) (int64, error) } var Orgs OrgsStore @@ -79,6 +80,11 @@ func (db *orgs) SearchByName(ctx context.Context, keyword string, page, pageSize return searchUserByName(ctx, db.DB, UserTypeOrganization, keyword, page, pageSize, orderBy) } +func (db *orgs) CountByUser(ctx context.Context, userID int64) (int64, error) { + var count int64 + return count, db.WithContext(ctx).Model(&OrgUser{}).Where("uid = ?", userID).Count(&count).Error +} + type Organization = User func (o *Organization) TableName() string { |