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 5 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,362 changes: 1,793 additions & 569 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/by-admin/{admin}";
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong preference but it looks like we have a couple formats for REST endpoints being used. Let's merge this as is and update REST endpoints throughout either using this format or another.

Opened #1152

}

// Batches queries for all batches with pagination.
rpc Batches(QueryBatchesRequest) returns (QueryBatchesResponse) {
option (google.api.http).get = "/regen/ecocredit/v1/batches";
Expand Down Expand Up @@ -231,6 +239,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
35 changes: 35 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,37 @@ $%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",
Example: `
$regen query ecocredit projects-by-admin regenx1v44...
$regen q ecocredit projects-by-admin regenx1v44.. --limit 10
`,
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