refactor: unit testable units and cleaner dep injection

This commit is contained in:
Arjun Patel
2026-04-27 16:07:28 -07:00
parent 013c453dd3
commit 48d6d5cb07
26 changed files with 761 additions and 617 deletions
+3 -5
View File
@@ -33,8 +33,6 @@ func newNetworkID() (networkID, error) {
return typeid.New[networkID]()
}
var errCapacityExceeded = errors.New("capacity exceeded")
type repository interface {
create(ctx context.Context, name, adminHumanId string) (*Network, error)
getByID(ctx context.Context, id string) (*Network, error)
@@ -47,6 +45,9 @@ type repository interface {
getNetworksForHuman(ctx context.Context, humanId string) ([]*Network, error)
isMember(ctx context.Context, networkID, humanId string) (bool, error)
listAll(ctx context.Context) ([]*Network, error)
// listAllMemberships returns humanId -> networkIds for every human with at
// least one membership. Humans with zero memberships are absent from the map.
listAllMemberships(ctx context.Context) (map[string][]string, error)
// Invitations
@@ -233,9 +234,6 @@ func (r *repositoryImpl) isMember(ctx context.Context, networkID, humanId string
return isMember, err
}
// listAllMemberships returns humanId -> networkIds for every human with at
// least one membership. Humans with zero memberships are absent from the map;
// callers layer them in separately.
func (r *repositoryImpl) listAllMemberships(ctx context.Context) (map[string][]string, error) {
rows, err := r.pool.Query(ctx, `SELECT human_id, network_id FROM network_members`)
if err != nil {