Skip to content

Commit

Permalink
[Session] Scaffold the GetSession query (#79)
Browse files Browse the repository at this point in the history
Just ran the following command:

```
ignite scaffold query get-session --module session --yes
```
  • Loading branch information
Olshansk authored Oct 19, 2023
1 parent 622b135 commit 34eeda0
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 6 deletions.
31 changes: 31 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46985,6 +46985,35 @@ paths:
additionalProperties: {}
tags:
- Query
/pocket/session/get_session:
get:
summary: Queries a list of GetSession items.
operationId: PocketSessionGetSession
responses:
'200':
description: A successful response.
schema:
type: object
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
/pocket/session/params:
get:
summary: Parameters queries the parameters of the module.
Expand Down Expand Up @@ -76228,6 +76257,8 @@ definitions:
pocket.session.Params:
type: object
description: Params defines the parameters for the module.
pocket.session.QueryGetSessionResponse:
type: object
pocket.session.QueryParamsResponse:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/math v1.0.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.1.0
Expand All @@ -21,6 +22,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -65,7 +67,6 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down Expand Up @@ -265,7 +266,6 @@ require (
gonum.org/v1/gonum v0.11.0 // indirect
google.golang.org/api v0.122.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
20 changes: 17 additions & 3 deletions proto/pocket/session/query.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package pocket.session;

import "gogoproto/gogo.proto";
Expand All @@ -10,17 +11,30 @@ option go_package = "pocket/x/session/types";

// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pocket/session/params";

}

// Queries a list of GetSession items.
rpc GetSession (QueryGetSessionRequest) returns (QueryGetSessionResponse) {
option (google.api.http).get = "/pocket/session/get_session";

}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {

// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
}

message QueryGetSessionRequest {}

message QueryGetSessionResponse {}

1 change: 0 additions & 1 deletion x/application/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"fmt"


sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
2 changes: 2 additions & 0 deletions x/session/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdGetSession())

// this line is used by starport scaffolding # 1

return cmd
Expand Down
42 changes: 42 additions & 0 deletions x/session/client/cli/query_get_session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"pocket/x/session/types"
)

var _ = strconv.Itoa(0)

func CmdGetSession() *cobra.Command {
cmd := &cobra.Command{
Use: "get-session",
Short: "Query get-session",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetSessionRequest{}

res, err := queryClient.GetSession(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
23 changes: 23 additions & 0 deletions x/session/keeper/query_get_session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"pocket/x/session/types"
)

func (k Keeper) GetSession(goCtx context.Context, req *types.QueryGetSessionRequest) (*types.QueryGetSessionResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Process the query
_ = ctx

return &types.QueryGetSessionResponse{}, nil
}

0 comments on commit 34eeda0

Please sign in to comment.