Skip to content

Commit

Permalink
Merge pull request #3 from kumparan/feature/message-with-tenantID
Browse files Browse the repository at this point in the history
feature: add tenantID in nats event message
  • Loading branch information
zhenqianz authored Feb 22, 2022
2 parents 0e2c548 + 9bd4427 commit e2528c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
15 changes: 12 additions & 3 deletions event_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
type (
// NatsEvent :nodoc:
NatsEvent struct {
ID int64
UserID int64
Subject string // empty on publish
ID int64
UserID int64
TenantID int64
Subject string // empty on publish
}

// NatsEventMessage :nodoc:
Expand Down Expand Up @@ -47,6 +48,14 @@ func (n *NatsEvent) GetUserID() int64 {
return n.UserID
}

// GetTenantID :nodoc:
func (n *NatsEvent) GetTenantID() int64 {
if n == nil {
return 0
}
return n.TenantID
}

// GetSubject :nodoc:
func (n *NatsEvent) GetSubject() string {
if n == nil {
Expand Down
11 changes: 10 additions & 1 deletion event_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ func TestNatsEventMessage_WithEvent(t *testing.T) {
ExpectedError bool
}{
{
Name: "success",
Name: "success without tenant id",
Given: &NatsEvent{
ID: 111,
UserID: 432,
},
ExpectedError: false,
},
{
Name: "success with tenant id",
Given: &NatsEvent{
ID: 111,
UserID: 432,
TenantID: 666,
},
ExpectedError: false,
},
{
Name: "empty id",
Given: &NatsEvent{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/kumparan/tapao v1.1.0
github.com/nats-io/nats.go v1.13.1-0.20211122170419-d7c1d78a50fc
github.com/pkg/errors v0.9.1
google.golang.org/protobuf v1.26.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
google.golang.org/protobuf v1.26.0
)

require (
Expand Down

0 comments on commit e2528c6

Please sign in to comment.