Skip to content

Commit

Permalink
fix(account): use user query in workspace interactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 8, 2024
1 parent 34752fb commit aa91351
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions account/accountusecase/accountinteractor/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ type UserQuery struct {
repos []accountrepo.User
}

func NewUserQuery(primary accountrepo.User, repos ...accountrepo.User) *UserQuery {
return &UserQuery{
repos: append([]accountrepo.User{primary}, repos...),
}
}

func (q *UserQuery) FetchByID(ctx context.Context, ids user.IDList) (user.List, error) {
var us user.List
for _, r := range q.repos {
Expand Down
4 changes: 3 additions & 1 deletion account/accountusecase/accountinteractor/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type WorkspaceMemberCountEnforcer func(context.Context, *workspace.Workspace, us
type Workspace struct {
repos *accountrepo.Container
enforceMemberCount WorkspaceMemberCountEnforcer
userquery accountinterfaces.UserQuery
}

func NewWorkspace(r *accountrepo.Container, enforceMemberCount WorkspaceMemberCountEnforcer) accountinterfaces.Workspace {
return &Workspace{
repos: r,
enforceMemberCount: enforceMemberCount,
userquery: NewUserQuery(r.User, r.Users...),
}
}

Expand Down Expand Up @@ -118,7 +120,7 @@ func (i *Workspace) AddUserMember(ctx context.Context, workspaceID workspace.ID,
return nil, workspace.ErrCannotModifyPersonalWorkspace
}

ul, err := i.repos.User.FindByIDs(ctx, maps.Keys(users))
ul, err := i.userquery.FetchByID(ctx, maps.Keys(users))
if err != nil {
return nil, err
}
Expand Down
54 changes: 54 additions & 0 deletions account/accountusecase/accountrepo/multiuser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package accountrepo

/* TODO
type MultiUser []User
func NewMultiUser(users ...User) MultiUser {
return MultiUser(users)
}
var _ User = MultiUser{}
func (u MultiUser) FindByID(ctx context.Context, id user.ID) (*user.User, error) {
for _, user := range u {
if res, err := user.FindByID(ctx, id); err != nil && !errors.Is(err, rerror.ErrNotFound) {
return nil, err
} else if res != nil {
return res, nil
}
}
return nil, nil
}
func (u MultiUser) FindByIDs(context.Context, user.IDList) (user.List, error) {
}
func (u MultiUser) FindBySub(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindByEmail(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindByName(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindByNameOrEmail(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindByVerification(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindByPasswordResetRequest(context.Context, string) (*user.User, error) {
}
func (u MultiUser) FindBySubOrCreate(context.Context, *user.User, string) (*user.User, error) {
}
*/

0 comments on commit aa91351

Please sign in to comment.