-
Notifications
You must be signed in to change notification settings - Fork 16
/
update.go
53 lines (46 loc) · 1.27 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package notebook
import (
"context"
"github.com/Bio-OS/bioos/internal/context/workspace/application/query/workspace"
"github.com/Bio-OS/bioos/internal/context/workspace/domain/notebook"
)
type UpdateCommand struct {
Name string
WorkspaceID string
Content []byte
}
// UpdateHandler ...
type UpdateHandler interface {
Handle(context.Context, *UpdateCommand) error
}
// NewUpdateHandler ...
func NewUpdateHandler(svc notebook.Service, workspaceReadModel workspace.WorkspaceReadModel) UpdateHandler {
return &updateHandler{
factory: notebook.NewFactory(),
service: svc,
workspaceReadModel: workspaceReadModel,
}
}
type updateHandler struct {
factory *notebook.Factory
service notebook.Service
workspaceReadModel workspace.WorkspaceReadModel
}
func (h *updateHandler) Handle(ctx context.Context, cmd *UpdateCommand) error {
if err := workspace.CheckWorkspaceExist(ctx, h.workspaceReadModel, cmd.WorkspaceID); err != nil {
return err
}
// TODO how to get and merge ?
nb, err := h.factory.New(¬ebook.CreateParam{
Name: cmd.Name,
WorkspaceID: cmd.WorkspaceID,
Content: cmd.Content,
})
if err != nil {
return err
}
if err := h.service.Update(ctx, nb); err != nil {
return err
}
return nil
}