Skip to content

Commit

Permalink
fix(account): fix workspace creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 8, 2024
1 parent cd93836 commit 72a0857
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion account/accountinfrastructure/accountmemory/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Workspace) FindByID(_ context.Context, v workspace.ID) (*workspace.Work
}), rerror.ErrNotFound)
}

func (r *Workspace) NewOne(_ context.Context, t *workspace.Workspace) error {
func (r *Workspace) Create(_ context.Context, t *workspace.Workspace) error {
if r.err != nil {
return r.err
}
Expand Down
11 changes: 1 addition & 10 deletions account/accountinfrastructure/accountmongo/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,7 @@ func (r *Workspace) FindByID(ctx context.Context, id accountdomain.WorkspaceID)

func (r *Workspace) Create(ctx context.Context, workspace *workspace.Workspace) error {
doc, id := mongodoc.NewWorkspace(workspace)
return r.client.NewOne(ctx, id, doc)
}

func (r *Workspace) NewOne(ctx context.Context, workspace *workspace.Workspace) error {
if !r.f.CanWrite(workspace.ID()) {
return accountrepo.ErrOperationDenied
}

doc, id := mongodoc.NewWorkspace(workspace)
return r.client.NewOne(ctx, id, doc)
return r.client.CreateOne(ctx, id, doc)
}

func (r *Workspace) Save(ctx context.Context, workspace *workspace.Workspace) error {
Expand Down
2 changes: 1 addition & 1 deletion account/accountusecase/accountinteractor/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (i *Workspace) Create(ctx context.Context, name string, firstUser workspace
return nil, err
}

if err := i.repos.Workspace.NewOne(ctx, ws); err != nil {
if err := i.repos.Workspace.Create(ctx, ws); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion account/accountusecase/accountrepo/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Workspace interface {
FindByIDs(context.Context, workspace.IDList) (workspace.List, error)
FindByUser(context.Context, user.ID) (workspace.List, error)
FindByIntegration(context.Context, workspace.IntegrationID) (workspace.List, error)
NewOne(context.Context, *workspace.Workspace) error
Create(context.Context, *workspace.Workspace) error
Save(context.Context, *workspace.Workspace) error
SaveAll(context.Context, workspace.List) error
Remove(context.Context, workspace.ID) error
Expand Down
6 changes: 5 additions & 1 deletion mongox/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ func (c *Collection) RemoveOne(ctx context.Context, f any) error {
return nil
}

func (c *Collection) NewOne(ctx context.Context, id string, doc any) error {
func (c *Collection) CreateOne(ctx context.Context, id string, doc any) error {
if id == "" {
return errors.New("id is empty")
}

count, err := c.collection.CountDocuments(ctx, bson.M{idKey: id})
if err != nil {
return wrapError(ctx, err)
Expand Down

0 comments on commit 72a0857

Please sign in to comment.