@@ -2,10 +2,11 @@ package handlers
2
2
3
3
import (
4
4
"context"
5
-
6
5
"github.com/iota-uz/iota-sdk/modules/core/domain/aggregates/user"
7
6
"github.com/iota-uz/iota-sdk/modules/core/domain/entities/tab"
7
+ "github.com/iota-uz/iota-sdk/modules/core/services"
8
8
"github.com/iota-uz/iota-sdk/pkg/application"
9
+ "github.com/iota-uz/iota-sdk/pkg/composables"
9
10
"github.com/iota-uz/iota-sdk/pkg/constants"
10
11
"github.com/iota-uz/iota-sdk/pkg/eventbus"
11
12
"github.com/iota-uz/iota-sdk/pkg/types"
@@ -14,20 +15,19 @@ import (
14
15
)
15
16
16
17
type TabHandler struct {
17
- app application.Application
18
- tabService tab. Repository
19
- logger * logrus.Logger
18
+ app application.Application
19
+ service * services. TabService
20
+ logger * logrus.Logger
20
21
}
21
22
22
23
func NewTabHandler (
23
24
app application.Application ,
24
- tabService tab.Repository ,
25
25
logger * logrus.Logger ,
26
26
) * TabHandler {
27
27
return & TabHandler {
28
- app : app ,
29
- tabService : tabService ,
30
- logger : logger ,
28
+ app : app ,
29
+ service : app . Service (services. TabService {}).( * services. TabService ) ,
30
+ logger : logger ,
31
31
}
32
32
}
33
33
@@ -36,7 +36,8 @@ func (h *TabHandler) Register(publisher eventbus.EventBus) {
36
36
}
37
37
38
38
func (h * TabHandler ) HandleUserCreated (event * user.CreatedEvent ) {
39
- h .createUserTabs (context .Background (), event .Result )
39
+ ctx := composables .WithPool (context .Background (), h .app .DB ())
40
+ h .createUserTabs (ctx , event .Result )
40
41
}
41
42
42
43
func (h * TabHandler ) createUserTabs (ctx context.Context , user user.User ) {
@@ -48,9 +49,9 @@ func (h *TabHandler) createUserTabs(ctx context.Context, user user.User) {
48
49
items := h .app .NavItems (i18n .NewLocalizer (h .app .Bundle (), string (user .UILanguage ())))
49
50
hrefs := h .getAccessibleNavItems (items , user )
50
51
51
- tabs := make ([]* tab.Tab , 0 , len (hrefs ))
52
+ tabs := make ([]* tab.CreateDTO , 0 , len (hrefs ))
52
53
for i , href := range hrefs {
53
- tabs = append (tabs , & tab.Tab {
54
+ tabs = append (tabs , & tab.CreateDTO {
54
55
UserID : user .ID (),
55
56
Href : href ,
56
57
Position : uint (i ),
@@ -59,13 +60,11 @@ func (h *TabHandler) createUserTabs(ctx context.Context, user user.User) {
59
60
60
61
if len (tabs ) > 0 {
61
62
ctxWithUser := context .WithValue (ctx , constants .UserKey , user )
62
- if err := h .tabService .DeleteUserTabs (ctxWithUser , user .ID ()); err != nil {
63
- h .logger .Errorf ("Failed to delete existing tabs for user %d: %v" , user .ID (), err )
63
+ _ , err := h .service .CreateManyUserTabs (ctxWithUser , user .ID (), tabs )
64
+ if err != nil {
65
+ h .logger .Errorf ("Failed to create tabs for user %d: %v" , user .ID (), err )
64
66
return
65
67
}
66
- if err := h .tabService .CreateMany (ctxWithUser , tabs ); err != nil {
67
- h .logger .Errorf ("Failed to create tab for user %d: %v" , user .ID (), err )
68
- }
69
68
}
70
69
}
71
70
0 commit comments