From 9bd4427057e98555901dbefd86bcc3e188cf3136 Mon Sep 17 00:00:00 2001 From: Agung Hariadi Tedja Date: Tue, 22 Feb 2022 10:02:12 +0700 Subject: [PATCH] feature: add tenantID in nats event message --- event_message.go | 15 ++++++++++++--- event_message_test.go | 11 ++++++++++- go.mod | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/event_message.go b/event_message.go index 2d84565..4838ca9 100644 --- a/event_message.go +++ b/event_message.go @@ -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: @@ -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 { diff --git a/event_message_test.go b/event_message_test.go index 04b138e..2b4677e 100644 --- a/event_message_test.go +++ b/event_message_test.go @@ -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{ diff --git a/go.mod b/go.mod index 49f00d4..2b895a3 100644 --- a/go.mod +++ b/go.mod @@ -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 (