Skip to content

Commit

Permalink
Made profiles query user parameter optional
Browse files Browse the repository at this point in the history
See PR #539
  • Loading branch information
dadamu authored Jul 27, 2021
1 parent afbcac0 commit a098636
Show file tree
Hide file tree
Showing 31 changed files with 817 additions and 710 deletions.
5 changes: 5 additions & 0 deletions .changeset/entries/2021-07-27T07:01:46Z.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: changed
module: x/profiles
pull_request: 539
description: Made profiles query user parameter optional
backward_compatible: true
11 changes: 11 additions & 0 deletions docs/developers/queries/profiles/application-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Query application links
This query allows you to retrieve the application links with the optional user `address`.

**CLI**
```bash
desmos query profiles app-links [[address]]

# Example
# desmos query app-links
# desmos query app-links desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud
```
11 changes: 11 additions & 0 deletions docs/developers/queries/profiles/blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Query blocked users
This query allows you to retrieve the user blocked list with the optional user `address`.

**CLI**
```bash
desmos query profiles blocks [[address]] [[subspace]]

# Example
# desmos query profiles blocks
# desmos query profiles blocks desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud
```
11 changes: 11 additions & 0 deletions docs/developers/queries/profiles/chain-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Query chain links
This query allows you to retrieve the chain links with the optional user `address`.

**CLI**
```bash
desmos query profiles chain-links [[address]]

# Example
# desmos query chain-links
# desmos query chain-links desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud
```
11 changes: 11 additions & 0 deletions docs/developers/queries/profiles/incoming-dtag-requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Query incoming DTag requests
This query allows you to retrieve the DTag requests with the optional user `address`.

**CLI**
```bash
desmos query profiles incoming-dtag-transfer-requests [[address]]

# Example
# desmos query profiles incoming-dtag-transfer-requests
# desmos query profiles incoming-dtag-transfer-requests desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud
```
11 changes: 11 additions & 0 deletions docs/developers/queries/profiles/relationships.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Query relationships
This query allows you to retrieve the relationships with the optional creator `address`.

**CLI**
```bash
desmos query profiles relationships [[address]]

# Example
# desmos query relationships
# desmos query relationships desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud
```
10 changes: 0 additions & 10 deletions docs/developers/queries/profiles/user-blocks.md

This file was deleted.

10 changes: 0 additions & 10 deletions docs/developers/queries/profiles/user-dtag-requests.md

This file was deleted.

10 changes: 0 additions & 10 deletions docs/developers/queries/profiles/user-relationships.md

This file was deleted.

8 changes: 5 additions & 3 deletions docs/developers/query-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ read the data stored inside it. Here you will find a list of all the query endpo
## Profiles

- [Query the stored profiles](queries/profiles/profile.md)
- [Query all the DTag transfer requests](queries/profiles/user-dtag-requests.md)
- [Query user's relationships](queries/profiles/user-relationships.md)
- [Query user's blocked users](queries/profiles/user-blocks.md)
- [Query incoming DTag transfer requests](queries/profiles/incoming-dtag-requests.md)
- [Query relationships](queries/profiles/relationships.md)
- [Query blocked users](queries/profiles/blocks.md)
- [Query chain links](queries/profiles/chain-links.md)
- [Query application links](queries/profiles/application-links.md)

## Posts

Expand Down
26 changes: 14 additions & 12 deletions proto/desmos/profiles/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ service Query {
option (google.api.http).get = "/desmos/profiles/v1beta1/params";
}

// UserRelationships queries the relationships for the user having the given
// address
rpc UserRelationships(QueryUserRelationshipsRequest)
returns (QueryUserRelationshipsResponse) {
// Relationships queries all relationships for the given user, if provided.
// Otherwise, it queries all the relationships stored.
rpc Relationships(QueryRelationshipsRequest)
returns (QueryRelationshipsResponse) {
option (google.api.http).get =
"/desmos/relationships/v1beta1/relationships/{user}";
}

// UserBlocks queries the user blocks for the user having the given address
rpc UserBlocks(QueryUserBlocksRequest) returns (QueryUserBlocksResponse) {
// Blocks queries the blocks for the given user, if provided.
// Otherwise, it queries all the stored blocks.
rpc Blocks(QueryBlocksRequest) returns (QueryBlocksResponse) {
option (google.api.http).get =
"/desmos/relationships/v1beta1/blocks/{user}";
}

// UserChainLinks queries chain links for the given user
rpc UserChainLinks(QueryUserChainLinksRequest)
returns (QueryUserChainLinksResponse) {
// ChainLinks queries the chain links associated to the given user, if provided.
// Otherwise it queries all the chain links stored.
rpc ChainLinks(QueryChainLinksRequest) returns (QueryChainLinksResponse) {
option (google.api.http).get =
"/desmos/profiles/v1beta1/chain-links/{user}";
}
Expand All @@ -66,9 +67,10 @@ service Query {
"/desmos/profiles/v1beta1/chain-links/{user}/{chain_name}/{target}";
}

// UserApplicationLinks queries application links for the given user
rpc UserApplicationLinks(QueryUserApplicationLinksRequest)
returns (QueryUserApplicationLinksResponse) {
// ApplicationLinks queries the applications links associated to the given user, if provided.
// Otherwise, it queries all the application links stored.
rpc ApplicationLinks(QueryApplicationLinksRequest)
returns (QueryApplicationLinksResponse) {
option (google.api.http).get = "/desmos/profiles/v1beta1/app-links/{user}";
}

Expand Down
8 changes: 4 additions & 4 deletions proto/desmos/profiles/v1beta1/query_app_links.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ message QueryUserApplicationLinkResponse {
ApplicationLink link = 1 [ (gogoproto.nullable) = false ];
}

// QueryUserApplicationLinksRequest represents the request used when querying
// QueryApplicationLinksRequest represents the request used when querying
// the application links of a specific user
message QueryUserApplicationLinksRequest {
message QueryApplicationLinksRequest {
string user = 1;

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

// QueryUserApplicationLinksResponse represents the response to the query used
// QueryApplicationLinksResponse represents the response to the query used
// to get the application links for a specific user
message QueryUserApplicationLinksResponse {
message QueryApplicationLinksResponse {
repeated ApplicationLink links = 1 [ (gogoproto.nullable) = false ];

// Pagination defines the pagination response
Expand Down
12 changes: 6 additions & 6 deletions proto/desmos/profiles/v1beta1/query_chain_links.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ message QueryUserChainLinkResponse {
ChainLink link = 1 [ (gogoproto.nullable) = false ];
}

// QueryUserChainLinksRequest is the request type for the
// Query/UserChainLinks RPC endpoint
message QueryUserChainLinksRequest {
// QueryChainLinksRequest is the request type for the
// Query/ChainLinks RPC endpoint
message QueryChainLinksRequest {
string user = 1;

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

// QueryUserChainLinksResponse is the response type for the
// Query/UserChainLinks RPC method.
message QueryUserChainLinksResponse {
// QueryChainLinksResponse is the response type for the
// Query/ChainLinks RPC method.
message QueryChainLinksResponse {
repeated ChainLink links = 1 [ (gogoproto.nullable) = false ];

// Pagination defines the pagination response
Expand Down
29 changes: 12 additions & 17 deletions proto/desmos/profiles/v1beta1/query_relationships.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/desmos-labs/desmos/x/profiles/types";

// QueryUserRelationshipsRequest is the request type for the
// Query/UserRelationships RPC method.
message QueryUserRelationshipsRequest {
// QueryRelationshipsRequest is the request type for the
// Query/Relationships RPC method.
message QueryRelationshipsRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

Expand All @@ -26,25 +26,21 @@ message QueryUserRelationshipsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryUserRelationshipsResponse is the response type for the
// Query/UserRelationships RPC method.
message QueryUserRelationshipsResponse {
string user = 1;

// relationships represent the list of all the relationships for the queried
// user
repeated desmos.profiles.v1beta1.Relationship relationships = 2
// QueryRelationshipsResponse is the response type for the
// Query/Relationships RPC method.
message QueryRelationshipsResponse {
repeated desmos.profiles.v1beta1.Relationship relationships = 1
[ (gogoproto.nullable) = false ];

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

// ___________________________________________________________________________________________________________________

// QueryUserBlocksRequest is the request type for the Query/UserBlocks RPC
// QueryBlocksRequest is the request type for the Query/Blocks RPC
// endpoint
message QueryUserBlocksRequest {
message QueryBlocksRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

Expand All @@ -54,10 +50,9 @@ message QueryUserBlocksRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryUserBlocksResponse is the response type for the Query/UserBlocks RPC
// QueryBlocksResponse is the response type for the Query/Blocks RPC
// method.
message QueryUserBlocksResponse {
// blocks represent the list of all the blocks for the queried user
message QueryBlocksResponse {
repeated desmos.profiles.v1beta1.UserBlock blocks = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
19 changes: 12 additions & 7 deletions x/profiles/client/cli/cli_app_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,32 @@ func GetCmdUnlinkApplication() *cobra.Command {

// -------------------------------------------------------------------------------------------------------------------

// GetCmdQueryUserApplicationsLinks returns the command allowing to query the application links associated with a profile
func GetCmdQueryUserApplicationsLinks() *cobra.Command {
// GetCmdQueryApplicationsLinks returns the command allowing to query the application links, optionally associated with a user
func GetCmdQueryApplicationsLinks() *cobra.Command {
cmd := &cobra.Command{
Use: "app-links [user]",
Short: "Get all the application links associated to the given username with optional pagination",
Args: cobra.ExactArgs(1),
Use: "app-links [[user]]",
Short: "Get all the application links with optional user address and pagination",
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

var user string
if len(args) == 1 {
user = args[0]
}

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

res, err := queryClient.UserApplicationLinks(
res, err := queryClient.ApplicationLinks(
context.Background(),
&types.QueryUserApplicationLinksRequest{User: args[0], Pagination: pageReq},
&types.QueryApplicationLinksRequest{User: user, Pagination: pageReq},
)
if err != nil {
return err
Expand Down
40 changes: 32 additions & 8 deletions x/profiles/client/cli/cli_app_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,57 @@ import (
"github.com/desmos-labs/desmos/x/profiles/types"
)

func (s *IntegrationTestSuite) TestCmdQueryUserApplicationsLinks() {
func (s *IntegrationTestSuite) TestCmdQueryApplicationsLinks() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
expectErr bool
expectedOutput types.QueryUserApplicationLinksResponse
expectedOutput types.QueryApplicationLinksResponse
}{
{
name: "no links found",
name: "existing links are returned properly",
args: []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
expectedOutput: types.QueryApplicationLinksResponse{
Links: []types.ApplicationLink{
types.NewApplicationLink(
"cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs",
types.NewData("reddit", "reddit-user"),
types.ApplicationLinkStateInitialized,
types.NewOracleRequest(
-1,
1,
types.NewOracleRequestCallData("twitter", "call_data"),
"client_id",
),
nil,
time.Date(2020, 1, 1, 00, 00, 00, 000, time.UTC),
),
},
},
},
{
name: "existing links of the given user address are not found",
args: []string{
"cosmos122u6u9gpdr2rp552fkkvlgyecjlmtqhkascl5a",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
expectedOutput: types.QueryUserApplicationLinksResponse{
expectedOutput: types.QueryApplicationLinksResponse{
Links: []types.ApplicationLink{},
},
},
{
name: "existing link is returned properly",
name: "existing links of the given user are returned properly",
args: []string{
"cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
expectedOutput: types.QueryUserApplicationLinksResponse{
expectedOutput: types.QueryApplicationLinksResponse{
Links: []types.ApplicationLink{
types.NewApplicationLink(
"cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs",
Expand All @@ -64,7 +88,7 @@ func (s *IntegrationTestSuite) TestCmdQueryUserApplicationsLinks() {
tc := tc

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

Expand All @@ -73,7 +97,7 @@ func (s *IntegrationTestSuite) TestCmdQueryUserApplicationsLinks() {
} else {
s.Require().NoError(err)

var response types.QueryUserApplicationLinksResponse
var response types.QueryApplicationLinksResponse
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(tc.expectedOutput.Links, response.Links)
}
Expand Down
Loading

0 comments on commit a098636

Please sign in to comment.