Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to paginate post reactions #515

Merged
merged 30 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2ada36e
Revise post reaction type
dadamu Jun 24, 2021
066f431
Revise keeper funcitons of post reaction
dadamu Jun 24, 2021
795df30
Fix genesis of cli test
dadamu Jun 24, 2021
d960fe6
Fix bugs oiterate functions
dadamu Jun 24, 2021
81a764c
Add post reactions query method
dadamu Jun 24, 2021
23cc1f5
Add post reactions query command
dadamu Jun 24, 2021
8b6b172
Add comment to commen functions
dadamu Jun 24, 2021
21a0933
Merge branch 'master' of github.com:desmos-labs/desmos into paul/add-…
dadamu Jun 25, 2021
8c56428
Fix fails after merge
dadamu Jun 25, 2021
40a2efa
Upadate docs
dadamu Jun 25, 2021
dac7e40
Update CHANGELOG
dadamu Jun 25, 2021
a40d56c
Run proto lint
dadamu Jun 25, 2021
4c1fac9
Fix benchmark test
dadamu Jun 25, 2021
c362065
Improve commom functions
dadamu Jun 25, 2021
ffe32ce
Remove space
dadamu Jun 25, 2021
00b6792
Adjust decoder test order
dadamu Jun 25, 2021
1a689b0
Fix typo and improve comments
dadamu Jun 25, 2021
83710f2
Add test to genesis in types
dadamu Jun 25, 2021
c68d011
Add unit test to keeper of reactions
dadamu Jun 25, 2021
16a76ba
Update x/staging/posts/keeper/common_functions.go
dadamu Jun 28, 2021
11bc583
Merge branch 'master' of github.com:desmos-labs/desmos into paul/add-…
dadamu Jun 28, 2021
25df337
Renaming cli post reactions into reactions
dadamu Jun 28, 2021
0ed0bab
Remove GetPostReactions function
dadamu Jun 28, 2021
db84db7
Update docs
dadamu Jun 28, 2021
c963c15
Merge branch 'paul/add-post-reactions-query' of github.com:desmos-lab…
dadamu Jun 28, 2021
729f491
Update CHANGELOG
dadamu Jun 28, 2021
7d87b57
Merge branch 'master' of github.com:desmos-labs/desmos into paul/add-…
RiccardoM Jun 30, 2021
9a0ec99
Update docs/developers/queries/staging/reactions.md
RiccardoM Jun 30, 2021
8c6846f
Update x/staging/posts/client/cli/query.go
RiccardoM Jun 30, 2021
a07edc3
Update docs/developers/queries/staging/reactions.md
RiccardoM Jun 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Added the ability to paginate user blocks ([#495](https://github.com/desmos-labs/desmos/issues/495))
- Added the post comments query ([#510](https://github.com/desmos-labs/desmos/pull/510))
- Added the ability to paginate incoming DTag transfer requests ([#519](https://github.com/desmos-labs/desmos/pull/519))
- Added the post reactions query and improved the methods of registered reactions ([#515](https://github.com/desmos-labs/desmos/pull/515))

# Version 0.16.3
## Changes
Expand Down
18 changes: 15 additions & 3 deletions docs/developers/queries/staging/reactions.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Query registered reactions
This query allows you to retrieve the list of registered reactions.
This query allows you to retrieve the list of registered reactions inside a optional subspace.
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved

**CLI**
```bash
desmos query posts registered-reactions
desmos query posts registered-reactions [[subspace-id]]

# Example
# desmos query posts registered-reactions
# desmos query posts registered-reactions 4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e
```

# Query post reactions
This query allows you to retrieve the list of post reactions of a post.
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved


**CLI**
```bash
desmos query posts reactions [post-id]

# Example
# desmos query posts reactions 301921ac3c8e623d8f35aef1886fea20849e49f08ec8ddfdd9b96feaf0c4fd15
```
2 changes: 1 addition & 1 deletion docs/developers/queries/staging/user-answers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This query allows you to retrieve the details of answers made to a post's poll'.

**CLI**
```bash
desmos query posts user-answers [id] [[user]]
desmos query posts user-answers [post-id] [[user]]

# Example
# desmos query posts user-answers a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc
Expand Down
16 changes: 3 additions & 13 deletions proto/desmos/posts/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ option go_package = "github.com/desmos-labs/desmos/x/staging/posts/types";
message GenesisState {
repeated desmos.posts.v1beta1.Post posts = 1 [ (gogoproto.nullable) = false ];

repeated UserAnswer users_poll_answers = 2 [ (gogoproto.nullable) = false ];
repeated PostReactionsEntry posts_reactions = 3
repeated desmos.posts.v1beta1.UserAnswer users_poll_answers = 2
[ (gogoproto.nullable) = false ];
repeated desmos.posts.v1beta1.PostReaction posts_reactions = 3
[ (gogoproto.nullable) = false ];
repeated desmos.posts.v1beta1.RegisteredReaction registered_reactions = 4
[ (gogoproto.nullable) = false ];
Expand All @@ -25,14 +26,3 @@ message GenesisState {
];
desmos.posts.v1beta1.Params params = 6 [ (gogoproto.nullable) = false ];
}

// PostReactionEntry represents an entry containing all the reactions to a post
message PostReactionsEntry {
string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.jsontag) = "post_id",
(gogoproto.moretags) = "yaml:\"post_id\""
];
repeated desmos.posts.v1beta1.PostReaction reactions = 2
[ (gogoproto.nullable) = false ];
}
38 changes: 35 additions & 3 deletions proto/desmos/posts/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ service Query {
option (google.api.http).get =
"/desmos/posts/v1beta1/posts/{post_id}/comments";
}

// PostReactions queries all the reactions of the post having the given id
rpc PostReactions(QueryPostReactionsRequest)
returns (QueryPostReactionsResponse) {
option (google.api.http).get =
"/desmos/posts/v1beta1/posts/{post_id}/reactions";
}
}

// ___________________________________________________________________________________________________________________
Expand Down Expand Up @@ -98,8 +105,10 @@ message QueryUserAnswersRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string post_id = 1
[ (gogoproto.jsontag) = "post_id", (gogoproto.moretags) = "yaml:\"id\"" ];
string post_id = 1 [
(gogoproto.jsontag) = "post_id",
(gogoproto.moretags) = "yaml:\"post_id\""
];

string user = 2;

Expand Down Expand Up @@ -132,7 +141,7 @@ message QueryRegisteredReactionsRequest {
// QueryRegisteredReactionsResponse is the response type for the
// Query/RegisteredReactions RPC method
message QueryRegisteredReactionsResponse {
repeated desmos.posts.v1beta1.RegisteredReaction registered_reactions = 1
repeated desmos.posts.v1beta1.RegisteredReaction reactions = 1
[ (gogoproto.nullable) = false ];

cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down Expand Up @@ -168,6 +177,29 @@ message QueryReportsResponse {

// ___________________________________________________________________________________________________________________

// QueryPostReactionsRequest is the request type for the Query/PostReactions RPC
// method.
message QueryPostReactionsRequest {
string post_id = 1 [
(gogoproto.jsontag) = "post_id",
(gogoproto.moretags) = "yaml:\"post_id\""
];

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryPostReactionsResponse is the response type for the Query/PostReactions
// RPC method
message QueryPostReactionsResponse {
repeated desmos.posts.v1beta1.PostReaction reactions = 1
[ (gogoproto.nullable) = false ];

cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// ___________________________________________________________________________________________________________________

// QueryPostCommentsRequest is the request type for the Query/PostComments RPC
// method.
message QueryPostCommentsRequest {
Expand Down
24 changes: 9 additions & 15 deletions proto/desmos/posts/v1beta1/reactions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,25 @@ message RegisteredReaction {
string creator = 4 [ (gogoproto.moretags) = "yaml:\"creator\"" ];
}

// RegisteredReactions wraps a list of registered reactions
message RegisteredReactions {
repeated desmos.posts.v1beta1.RegisteredReaction reactions = 1
[ (gogoproto.nullable) = false ];
}

// ___________________________________________________________________________________________________________________

// PostReaction is a struct of a user reaction to a post
message PostReaction {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

string short_code = 1 [
string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.jsontag) = "post_id",
(gogoproto.moretags) = "yaml:\"post_id\""
];

string short_code = 2 [
(gogoproto.moretags) = "yaml:\"short_code\"",
(gogoproto.jsontag) = "short_code"
];

string value = 2 [ (gogoproto.moretags) = "yaml:\"value\"" ];

string owner = 3 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
}
string value = 3 [ (gogoproto.moretags) = "yaml:\"value\"" ];

// PostReactions wraps a list of post reactions
message PostReactions {
repeated desmos.posts.v1beta1.PostReaction reactions = 1
[ (gogoproto.nullable) = false ];
string owner = 4 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
}
78 changes: 65 additions & 13 deletions x/staging/posts/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type IntegrationTestSuite struct {

func TestIntegrationTestSuite(t *testing.T) {
//TODO restore this when out of staging
// suite.Run(t, new(IntegrationTestSuite))
//suite.Run(t, new(IntegrationTestSuite))
}

func (s *IntegrationTestSuite) SetupSuite() {
Expand Down Expand Up @@ -114,16 +114,13 @@ func (s *IntegrationTestSuite) SetupSuite() {
[]string{"1"},
),
}
postsData.PostsReactions = []types.PostReactionsEntry{
types.NewPostReactionsEntry(
postsData.PostsReactions = []types.PostReaction{
types.NewPostReaction(
"19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
[]types.PostReaction{
types.NewPostReaction(
":broken_heart:",
"💔",
"cosmos12t08qkk4dm2pqgyy8hmq5hx92y2m29zedmdw7f",
),
}),
":broken_heart:",
"💔",
"cosmos12t08qkk4dm2pqgyy8hmq5hx92y2m29zedmdw7f",
),
}

postsData.Reports = []types.Report{
Expand Down Expand Up @@ -406,7 +403,7 @@ func (s *IntegrationTestSuite) TestCmdQueryRegisteredReactions() {
args: []string{fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
expectErr: false,
expectedOutput: types.QueryRegisteredReactionsResponse{
RegisteredReactions: []types.RegisteredReaction{
Reactions: []types.RegisteredReaction{
types.NewRegisteredReaction(
"cosmos1lhhkerae9cu3fa442vt50t32grlajun5lmrv3g",
":reaction:",
Expand All @@ -431,7 +428,7 @@ func (s *IntegrationTestSuite) TestCmdQueryRegisteredReactions() {
args: []string{"4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e", fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
expectErr: false,
expectedOutput: types.QueryRegisteredReactionsResponse{
RegisteredReactions: []types.RegisteredReaction{
Reactions: []types.RegisteredReaction{
types.NewRegisteredReaction(
"cosmos1lhhkerae9cu3fa442vt50t32grlajun5lmrv3g",
":reaction:",
Expand All @@ -454,7 +451,7 @@ func (s *IntegrationTestSuite) TestCmdQueryRegisteredReactions() {
},
expectErr: false,
expectedOutput: types.QueryRegisteredReactionsResponse{
RegisteredReactions: []types.RegisteredReaction{
Reactions: []types.RegisteredReaction{
types.NewRegisteredReaction(
"cosmos1s3nh6tafl4amaxkke9kdejhp09lk93g9ev39r4",
":smile-jpg:",
Expand Down Expand Up @@ -647,6 +644,61 @@ func (s *IntegrationTestSuite) TestCmdQueryPostComments() {
}
}

func (s *IntegrationTestSuite) TestCmdQueryPostReactions() {
val := s.network.Validators[0]

testCases := []struct {
name string
args []string
shouldErr bool
expectedOutput types.QueryPostReactionsResponse
}{
{
name: "valid request is returned properly",
args: []string{
"19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
shouldErr: false,
expectedOutput: types.QueryPostReactionsResponse{
Reactions: []types.PostReaction{
types.NewPostReaction(
"19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
":broken_heart:",
"💔",
"cosmos12t08qkk4dm2pqgyy8hmq5hx92y2m29zedmdw7f",
),
},
Pagination: &query.PageResponse{
NextKey: nil,
Total: 0,
},
},
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryPostReactions()
clientCtx := val.ClientCtx
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.shouldErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)

var response types.QueryPostReactionsResponse
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(tc.expectedOutput.Reactions, response.Reactions)
s.Require().Equal(tc.expectedOutput.Pagination, response.Pagination)
}
})
}
}

// ___________________________________________________________________________________________________________________

func (s *IntegrationTestSuite) TestCmdCreatePost() {
Expand Down
41 changes: 39 additions & 2 deletions x/staging/posts/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryUserAnswers(),
GetCmdQueryRegisteredReactions(),
GetCmdQueryParams(),
GetCmdQueryPostReactions(),
)
return postQueryCmd
}
Expand Down Expand Up @@ -159,7 +160,7 @@ func GetCmdQueryUserAnswers() *cobra.Command {
func GetCmdQueryRegisteredReactions() *cobra.Command {
cmd := &cobra.Command{
Use: "registered-reactions [[subspace-id]]",
Short: "Retrieve tha registered reactions with optional subspace",
Short: "Retrieve the registered reactions with optional subspace",
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -253,11 +254,47 @@ func GetCmdQueryParams() *cobra.Command {
return cmd
}

// GetCmdQueryPostReactions returns the command allowing to query the reactions of a post
func GetCmdQueryPostReactions() *cobra.Command {
cmd := &cobra.Command{
Use: "reactions [post-id]",
Short: "Retrieve the reactions of the post having the given id",
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

res, err := queryClient.PostReactions(
context.Background(),
&types.QueryPostReactionsRequest{PostId: args[0], Pagination: pageReq},
)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, types.QueryPostReactions)

return cmd
}

// GetCmdQueryPostComments returns the command allowing to query the comments of a post
func GetCmdQueryPostComments() *cobra.Command {
cmd := &cobra.Command{
Use: "post-comments [post-id]",
Short: "Retrieve tha comments of the post with the given id",
Short: "Retrieve the comments of the post with the given id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down
Loading