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

feat(ecocredit): add projects by admin query #1141

Merged
merged 6 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2,371 changes: 1,797 additions & 574 deletions api/regen/ecocredit/v1/query.pulsar.go

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions api/regen/ecocredit/v1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions proto/regen/ecocredit/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ service Query {
option (google.api.http).get = "/regen/ecocredit/v1/projects/{project_id}";
}

// ProjectsByAdmin queries for all projects by admin with
// pagination.
rpc ProjectsByAdmin(QueryProjectsByAdminRequest)
returns (QueryProjectsByAdminResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1/projects/{admin}";
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
}

// Batches queries for all batches with pagination.
rpc Batches(QueryBatchesRequest) returns (QueryBatchesResponse) {
option (google.api.http).get =
Expand Down Expand Up @@ -230,6 +238,26 @@ message QueryProjectsByReferenceIdResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryProjectsByAdminRequest is the Query/ProjectByAdmin request type.
message QueryProjectsByAdminRequest {

// admin is the account address of project admin.
string admin = 1;

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

// QueryProjectsByAdminResponse is the Query/ProjectByAdmin response type.
message QueryProjectsByAdminResponse {

// projects are the fetched projects.
repeated ProjectInfo projects = 1;

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryProjectRequest is the Query/Project request type.
message QueryProjectRequest {

Expand Down
39 changes: 39 additions & 0 deletions x/ecocredit/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func QueryCmd(name string) *cobra.Command {
QueryCreditTypesCmd(),
QueryProjectsCmd(),
QueryProjectsByReferenceIdCmd(),
QueryProjectsByAdminCmd(),
QueryProjectCmd(),
QueryParamsCmd(),
basketcli.QueryBasketCmd(),
Expand Down Expand Up @@ -495,3 +496,41 @@ $%s q %s projects-by-reference-id R1 --limit 10

return qflags(cmd)
}

// QueryProjectsByAdminCmd returns command that retrieves list of projects by admin with pagination.
func QueryProjectsByAdminCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "projects-by-admin [admin]",
Short: "Retrieve list of projects by admin with pagination flags",
Long: strings.TrimSpace(
fmt.Sprintf(`Retrieve list of projects by admin with pagination flags

Examples:
$%s query %s projects-by-admin regenx1v44...
$%s q %s projects-by-admin regenx1v44.. --limit 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use Example for examples.

Documentation generated using Example:

Documentation with examples in the Long description:

`, version.AppName, ecocredit.ModuleName, version.AppName, ecocredit.ModuleName),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, ctx, err := mkQueryClient(cmd)
if err != nil {
return err
}

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

res, err := c.ProjectsByAdmin(cmd.Context(), &core.QueryProjectsByAdminRequest{
Admin: args[0],
Pagination: pagination,
})
return printQueryResponse(ctx, res, err)
},
}

flags.AddPaginationFlagsToCmd(cmd, "projects-by-admin")

return qflags(cmd)
}
Loading