Skip to content

Commit 6436fbb

Browse files
committed
refactor(context): remove message type aliases
1 parent 60779a3 commit 6436fbb

39 files changed

Lines changed: 108 additions & 132 deletions

File tree

internal/pkg/service/communication/command/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ type (
1919
Handler = commands.Handler
2020
)
2121

22-
func New(key commands.Key, attributes, meta any) *commands.Command {
23-
return messages.New[commands.Command](key, attributes, meta)
22+
func New(key messages.Key, attributes, meta any) *messages.Message {
23+
return messages.New(key, attributes, meta)
2424
}

internal/pkg/service/communication/query/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ type (
1919
Handler = queries.Handler
2020
)
2121

22-
func New(key queries.Key, attributes, meta any) *queries.Query {
23-
return messages.New[queries.Query](key, attributes, meta)
22+
func New(key messages.Key, attributes, meta any) *messages.Message {
23+
return messages.New(key, attributes, meta)
2424
}

pkg/context/notification/application/confirmation/consumer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package confirmation
33
import (
44
"github.com/bastean/codexgo/v4/pkg/context/notification/domain/cases"
55
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
6-
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/events"
76
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/events/user"
7+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
88
)
99

1010
type Consumer struct {
1111
cases.Confirmation
1212
}
1313

14-
func (c *Consumer) On(event *events.Event) error {
14+
func (c *Consumer) On(event *messages.Message) error {
1515
account, ok := event.Attributes.(*user.CreatedSucceededAttributes)
1616

1717
if !ok {

pkg/context/notification/application/confirmation/consumer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (s *ConfirmationTestSuite) SetupTest() {
3333
}
3434

3535
func (s *ConfirmationTestSuite) TestConsumer() {
36-
event := messages.RandomWithAttributes[events.Event](new(user.CreatedSucceededAttributes), true)
36+
event := messages.RandomWithAttributes(new(user.CreatedSucceededAttributes), true)
3737

3838
s.transfer.Mock.On("Submit", event.Attributes)
3939

pkg/context/shared/domain/aggregates/root.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package aggregates
22

33
import (
44
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/errors"
5-
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/events"
5+
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
66
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/services"
77
)
88

99
type Root struct {
1010
Created, Updated *Time
11-
Events []*events.Event
11+
Events []*messages.Message
1212
}
1313

1414
func (r *Root) CreationStamp() error {
@@ -26,7 +26,6 @@ func (r *Root) CreationStamp() error {
2626
}
2727

2828
r.Created = created
29-
3029
r.Updated = created
3130

3231
return nil
@@ -44,20 +43,20 @@ func (r *Root) UpdatedStamp() error {
4443
return nil
4544
}
4645

47-
func (r *Root) Record(events ...*events.Event) {
46+
func (r *Root) Record(events ...*messages.Message) {
4847
r.Events = append(r.Events, events...)
4948
}
5049

51-
func (r *Root) Pull() []*events.Event {
50+
func (r *Root) Pull() []*messages.Message {
5251
recorded := r.Events
5352

54-
r.Events = []*events.Event{}
53+
r.Events = []*messages.Message{}
5554

5655
return recorded
5756
}
5857

5958
func NewRoot() (*Root, error) {
6059
return &Root{
61-
Events: []*events.Event{},
60+
Events: []*messages.Message{},
6261
}, nil
6362
}

pkg/context/shared/domain/commands/command.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ import (
44
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
55
)
66

7-
type (
8-
Key = messages.Key
9-
)
10-
11-
type Command messages.Message
12-
137
type Handler interface {
14-
Handle(*Command) error
8+
Handle(*messages.Message) error
159
}
1610

1711
type Bus interface {
18-
Register(Key, Handler) error
19-
Dispatch(*Command) error
12+
Register(messages.Key, Handler) error
13+
Dispatch(*messages.Message) error
2014
}

pkg/context/shared/domain/events/event.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ import (
44
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
55
)
66

7-
type (
8-
Key = messages.Key
9-
Recipient = messages.Recipient
10-
)
11-
12-
type Event messages.Message
13-
147
type Consumer interface {
15-
On(*Event) error
8+
On(*messages.Message) error
169
}
1710

1811
type Bus interface {
19-
Subscribe(Key, Consumer) error
20-
Publish(*Event) error
12+
Subscribe(messages.Key, Consumer) error
13+
Publish(*messages.Message) error
2114
}

pkg/context/shared/domain/messages/key_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/stretchr/testify/suite"
77

8-
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/events"
98
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/messages"
109
)
1110

@@ -24,7 +23,7 @@ func (s *KeyTestSuite) TestWithValidValue() {
2423
Status: messages.Status.Succeeded,
2524
}
2625

27-
expected := events.Key("codexgo.user.1.event.user.created.succeeded")
26+
expected := messages.Key("codexgo.user.1.event.user.created.succeeded")
2827

2928
actual := messages.NewKey(components)
3029

pkg/context/shared/domain/messages/message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package messages
22

3-
type Message = struct {
3+
type Message struct {
44
ID string
55
OccurredOn string
66
Key Key
77
Attributes any
88
Meta any
99
}
1010

11-
func New[T ~Message](key Key, attributes, meta any) *T {
12-
return &T{
11+
func New(key Key, attributes, meta any) *Message {
12+
return &Message{
1313
Key: key,
1414
Attributes: attributes,
1515
Meta: meta,

pkg/context/shared/domain/messages/message.mother.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"github.com/bastean/codexgo/v4/pkg/context/shared/domain/services"
66
)
77

8-
func Random[T ~Message]() *T {
9-
return &T{
8+
func Random() *Message {
9+
return &Message{
1010
ID: services.Create.UUID(),
1111
OccurredOn: services.Create.TimeZoneFull(),
1212
Key: Key(services.Create.LoremIpsumWord()),
@@ -15,8 +15,8 @@ func Random[T ~Message]() *T {
1515
}
1616
}
1717

18-
func RandomWithKey[T ~Message](key Key) *T {
19-
return &T{
18+
func RandomWithKey(key Key) *Message {
19+
return &Message{
2020
ID: services.Create.UUID(),
2121
OccurredOn: services.Create.TimeZoneFull(),
2222
Key: key,
@@ -25,7 +25,7 @@ func RandomWithKey[T ~Message](key Key) *T {
2525
}
2626
}
2727

28-
func RandomWithAttributes[T ~Message](attributes any, shouldRandomize bool) *T {
28+
func RandomWithAttributes(attributes any, shouldRandomize bool) *Message {
2929
if shouldRandomize {
3030
err := services.Create.Struct(attributes)
3131

@@ -34,7 +34,7 @@ func RandomWithAttributes[T ~Message](attributes any, shouldRandomize bool) *T {
3434
}
3535
}
3636

37-
return &T{
37+
return &Message{
3838
ID: services.Create.UUID(),
3939
OccurredOn: services.Create.TimeZoneFull(),
4040
Key: Key(services.Create.LoremIpsumWord()),

0 commit comments

Comments
 (0)