Keepers 680ec2b751
adding fault/clues to non-service connector pkgs (#2380)
## Does this PR need a docs update or release note?

- [x]  No 

## Type of change

- [x] 🧹 Tech Debt/Cleanup

## Issue(s)

* #1970

## Test Plan

- [x]  Unit test
- [x] 💚 E2E
2023-02-13 16:54:09 +00:00

56 lines
1.4 KiB
Go

package discovery
import (
"context"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/connector/discovery/api"
"github.com/alcionai/corso/src/pkg/fault"
)
// ---------------------------------------------------------------------------
// interfaces
// ---------------------------------------------------------------------------
type getAller interface {
GetAll(context.Context, *fault.Errors) ([]models.Userable, error)
}
type getter interface {
GetByID(context.Context, string) (models.Userable, error)
}
type getInfoer interface {
GetInfo(context.Context, string) (*api.UserInfo, error)
}
type getWithInfoer interface {
getter
getInfoer
}
// ---------------------------------------------------------------------------
// api
// ---------------------------------------------------------------------------
// Users fetches all users in the tenant.
func Users(ctx context.Context, ga getAller, errs *fault.Errors) ([]models.Userable, error) {
return ga.GetAll(ctx, errs)
}
func User(ctx context.Context, gwi getWithInfoer, userID string) (models.Userable, *api.UserInfo, error) {
u, err := gwi.GetByID(ctx, userID)
if err != nil {
return nil, nil, errors.Wrap(err, "getting user")
}
ui, err := gwi.GetInfo(ctx, userID)
if err != nil {
return nil, nil, errors.Wrap(err, "getting user info")
}
return u, ui, nil
}