-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a query to get a feed message by sequence number (#78)
- Loading branch information
Showing
12 changed files
with
245 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package queries | ||
|
||
import ( | ||
"github.com/boreq/errors" | ||
"github.com/planetary-social/scuttlego/service/domain/feeds/message" | ||
"github.com/planetary-social/scuttlego/service/domain/refs" | ||
) | ||
|
||
type GetMessageBySequence struct { | ||
feed refs.Feed | ||
sequence message.Sequence | ||
} | ||
|
||
func NewGetMessageBySequence(feed refs.Feed, sequence message.Sequence) (GetMessageBySequence, error) { | ||
if feed.IsZero() { | ||
return GetMessageBySequence{}, errors.New("zero value of feed") | ||
} | ||
if sequence.IsZero() { | ||
return GetMessageBySequence{}, errors.New("zero value of sequence") | ||
} | ||
return GetMessageBySequence{feed: feed, sequence: sequence}, nil | ||
} | ||
|
||
func (q *GetMessageBySequence) Feed() refs.Feed { | ||
return q.feed | ||
} | ||
|
||
func (q *GetMessageBySequence) Sequence() message.Sequence { | ||
return q.sequence | ||
} | ||
|
||
func (q *GetMessageBySequence) IsZero() bool { | ||
return q.feed.IsZero() | ||
} | ||
|
||
type GetMessageBySequenceHandler struct { | ||
feedRepository FeedRepository | ||
} | ||
|
||
func NewGetMessageBySequenceHandler(feedRepository FeedRepository) *GetMessageBySequenceHandler { | ||
return &GetMessageBySequenceHandler{feedRepository: feedRepository} | ||
} | ||
|
||
func (h *GetMessageBySequenceHandler) Handle(query GetMessageBySequence) (message.Message, error) { | ||
if query.IsZero() { | ||
return message.Message{}, errors.New("zero value of query") | ||
} | ||
|
||
return h.feedRepository.GetMessage(query.Feed(), query.Sequence()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package queries_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/planetary-social/scuttlego/di" | ||
"github.com/planetary-social/scuttlego/fixtures" | ||
"github.com/planetary-social/scuttlego/service/adapters/mocks" | ||
"github.com/planetary-social/scuttlego/service/app/queries" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetMessageBySequenceHandler(t *testing.T) { | ||
tq, err := di.BuildTestQueries(t) | ||
require.NoError(t, err) | ||
|
||
feed := fixtures.SomeRefFeed() | ||
sequence := fixtures.SomeSequence() | ||
|
||
query, err := queries.NewGetMessageBySequence(feed, sequence) | ||
require.NoError(t, err) | ||
|
||
expectedMessage := fixtures.SomeMessage(sequence, feed) | ||
tq.FeedRepository.GetMessageReturnValue = expectedMessage | ||
|
||
msg, err := tq.Queries.GetMessageBySequence.Handle(query) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedMessage, msg) | ||
require.Equal(t, | ||
[]mocks.FeedRepositoryMockGetMessageCall{ | ||
{ | ||
Feed: feed, | ||
Seq: sequence, | ||
}, | ||
}, | ||
tq.FeedRepository.GetMessageCalls, | ||
) | ||
} |