Unverified Commit 6d9c1399 authored by Flávio Fernandes's avatar Flávio Fernandes Committed by GitHub
Browse files

Add pagination support for the wallet ledger (#699)

* GetWalletLedger rpc to support pagination

* Add forward and backward pagination functionality of the GetWalletLedger rpc

* Extend the wallet page to support pagination

* Avoid DRY for the wallet ledger pagination query's construction
parent df2e6bfc
Loading
Loading
Loading
Loading
+461 −352

File changed.

Preview size limit exceeded, changes collapsed.

+29 −11
Original line number Diff line number Diff line
@@ -1451,8 +1451,12 @@ func local_request_Console_GetStorage_0(ctx context.Context, marshaler runtime.M

}

var (
	filter_Console_GetWalletLedger_0 = &utilities.DoubleArray{Encoding: map[string]int{"account_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)

func request_Console_GetWalletLedger_0(ctx context.Context, marshaler runtime.Marshaler, client ConsoleClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq AccountId
	var protoReq GetWalletLedgerRequest
	var metadata runtime.ServerMetadata

	var (
@@ -1462,14 +1466,21 @@ func request_Console_GetWalletLedger_0(ctx context.Context, marshaler runtime.Ma
		_   = err
	)

	val, ok = pathParams["id"]
	val, ok = pathParams["account_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "account_id")
	}

	protoReq.Id, err = runtime.String(val)
	protoReq.AccountId, err = runtime.String(val)
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "account_id", err)
	}

	if err := req.ParseForm(); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}
	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Console_GetWalletLedger_0); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := client.GetWalletLedger(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
@@ -1478,7 +1489,7 @@ func request_Console_GetWalletLedger_0(ctx context.Context, marshaler runtime.Ma
}

func local_request_Console_GetWalletLedger_0(ctx context.Context, marshaler runtime.Marshaler, server ConsoleServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq AccountId
	var protoReq GetWalletLedgerRequest
	var metadata runtime.ServerMetadata

	var (
@@ -1488,14 +1499,21 @@ func local_request_Console_GetWalletLedger_0(ctx context.Context, marshaler runt
		_   = err
	)

	val, ok = pathParams["id"]
	val, ok = pathParams["account_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "account_id")
	}

	protoReq.Id, err = runtime.String(val)
	protoReq.AccountId, err = runtime.String(val)
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "account_id", err)
	}

	if err := req.ParseForm(); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}
	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Console_GetWalletLedger_0); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := server.GetWalletLedger(ctx, &protoReq)
@@ -4668,7 +4686,7 @@ var (

	pattern_Console_GetStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"v2", "console", "storage", "collection", "key", "user_id"}, ""))

	pattern_Console_GetWalletLedger_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"v2", "console", "account", "id", "wallet"}, ""))
	pattern_Console_GetWalletLedger_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"v2", "console", "account", "account_id", "wallet"}, ""))

	pattern_Console_ListApiEndpoints_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "console", "api", "endpoints"}, ""))

+15 −2
Original line number Diff line number Diff line
@@ -221,8 +221,8 @@ service Console {
  }

  // Get a list of the user's wallet transactions.
  rpc GetWalletLedger (AccountId) returns (WalletLedgerList) {
    option (google.api.http).get = "/v2/console/account/{id}/wallet";
  rpc GetWalletLedger (GetWalletLedgerRequest) returns (WalletLedgerList) {
    option (google.api.http).get = "/v2/console/account/{account_id}/wallet";
  }

  // API Explorer - list all endpoints
@@ -777,6 +777,10 @@ message WalletLedger {
message WalletLedgerList {
  // A list of wallet ledger items.
  repeated WalletLedger items = 1;
  // The cursor to send when retrieving the next older page, if any.
  string next_cursor = 2;
  // The cursor to send when retrieving the previous page newer, if any.
  string prev_cursor = 3;
}

// Write a new storage object or update an existing one.
@@ -796,3 +800,12 @@ message WriteStorageObjectRequest {
  // Write permission value.
  google.protobuf.Int32Value permission_write = 7;
}

message GetWalletLedgerRequest{
  // The unique identifier of the user account.
  string account_id = 1;
  // Max number of results per page
  uint32 limit = 2;
  // Cursor to retrieve a page of records from
  string cursor = 3;
}
+55 −32
Original line number Diff line number Diff line
@@ -92,6 +92,53 @@
        ]
      }
    },
    "/v2/console/account/{accountId}/wallet": {
      "get": {
        "summary": "Get a list of the user's wallet transactions.",
        "operationId": "Console_GetWalletLedger",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/consoleWalletLedgerList"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/googlerpcStatus"
            }
          }
        },
        "parameters": [
          {
            "name": "accountId",
            "description": "The unique identifier of the user account.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "limit",
            "description": "Max number of results per page.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int64"
          },
          {
            "name": "cursor",
            "description": "Cursor to retrieve a page of records from.",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Console"
        ]
      }
    },
    "/v2/console/account/{id}": {
      "get": {
        "summary": "Get detailed account information for a single user.",
@@ -733,38 +780,6 @@
        ]
      }
    },
    "/v2/console/account/{id}/wallet": {
      "get": {
        "summary": "Get a list of the user's wallet transactions.",
        "operationId": "Console_GetWalletLedger",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/consoleWalletLedgerList"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/googlerpcStatus"
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "description": "The unique identifier of the user account.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "Console"
        ]
      }
    },
    "/v2/console/account/{id}/wallet/{walletId}": {
      "delete": {
        "summary": "Delete a wallet ledger item.",
@@ -2753,6 +2768,14 @@
            "$ref": "#/definitions/consoleWalletLedger"
          },
          "description": "A list of wallet ledger items."
        },
        "nextCursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the next older page, if any."
        },
        "prevCursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the previous page newer, if any."
        }
      },
      "description": "List of wallet ledger items for a particular user."
+13 −9
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import (

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7

// ConsoleClient is the client API for Console service.
@@ -70,7 +71,7 @@ type ConsoleClient interface {
	// Get a storage object.
	GetStorage(ctx context.Context, in *api.ReadStorageObjectId, opts ...grpc.CallOption) (*api.StorageObject, error)
	// Get a list of the user's wallet transactions.
	GetWalletLedger(ctx context.Context, in *AccountId, opts ...grpc.CallOption) (*WalletLedgerList, error)
	GetWalletLedger(ctx context.Context, in *GetWalletLedgerRequest, opts ...grpc.CallOption) (*WalletLedgerList, error)
	// API Explorer - list all endpoints
	ListApiEndpoints(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ApiEndpointList, error)
	// List leaderboard records.
@@ -348,7 +349,7 @@ func (c *consoleClient) GetStorage(ctx context.Context, in *api.ReadStorageObjec
	return out, nil
}

func (c *consoleClient) GetWalletLedger(ctx context.Context, in *AccountId, opts ...grpc.CallOption) (*WalletLedgerList, error) {
func (c *consoleClient) GetWalletLedger(ctx context.Context, in *GetWalletLedgerRequest, opts ...grpc.CallOption) (*WalletLedgerList, error) {
	out := new(WalletLedgerList)
	err := c.cc.Invoke(ctx, "/nakama.console.Console/GetWalletLedger", in, out, opts...)
	if err != nil {
@@ -601,7 +602,7 @@ type ConsoleServer interface {
	// Get a storage object.
	GetStorage(context.Context, *api.ReadStorageObjectId) (*api.StorageObject, error)
	// Get a list of the user's wallet transactions.
	GetWalletLedger(context.Context, *AccountId) (*WalletLedgerList, error)
	GetWalletLedger(context.Context, *GetWalletLedgerRequest) (*WalletLedgerList, error)
	// API Explorer - list all endpoints
	ListApiEndpoints(context.Context, *emptypb.Empty) (*ApiEndpointList, error)
	// List leaderboard records.
@@ -726,7 +727,7 @@ func (UnimplementedConsoleServer) GetStatus(context.Context, *emptypb.Empty) (*S
func (UnimplementedConsoleServer) GetStorage(context.Context, *api.ReadStorageObjectId) (*api.StorageObject, error) {
	return nil, status.Errorf(codes.Unimplemented, "method GetStorage not implemented")
}
func (UnimplementedConsoleServer) GetWalletLedger(context.Context, *AccountId) (*WalletLedgerList, error) {
func (UnimplementedConsoleServer) GetWalletLedger(context.Context, *GetWalletLedgerRequest) (*WalletLedgerList, error) {
	return nil, status.Errorf(codes.Unimplemented, "method GetWalletLedger not implemented")
}
func (UnimplementedConsoleServer) ListApiEndpoints(context.Context, *emptypb.Empty) (*ApiEndpointList, error) {
@@ -801,8 +802,8 @@ type UnsafeConsoleServer interface {
	mustEmbedUnimplementedConsoleServer()
}

func RegisterConsoleServer(s *grpc.Server, srv ConsoleServer) {
	s.RegisterService(&_Console_serviceDesc, srv)
func RegisterConsoleServer(s grpc.ServiceRegistrar, srv ConsoleServer) {
	s.RegisterService(&Console_ServiceDesc, srv)
}

func _Console_Authenticate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
@@ -1256,7 +1257,7 @@ func _Console_GetStorage_Handler(srv interface{}, ctx context.Context, dec func(
}

func _Console_GetWalletLedger_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(AccountId)
	in := new(GetWalletLedgerRequest)
	if err := dec(in); err != nil {
		return nil, err
	}
@@ -1268,7 +1269,7 @@ func _Console_GetWalletLedger_Handler(srv interface{}, ctx context.Context, dec
		FullMethod: "/nakama.console.Console/GetWalletLedger",
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ConsoleServer).GetWalletLedger(ctx, req.(*AccountId))
		return srv.(ConsoleServer).GetWalletLedger(ctx, req.(*GetWalletLedgerRequest))
	}
	return interceptor(ctx, in, info, handler)
}
@@ -1651,7 +1652,10 @@ func _Console_WriteStorageObject_Handler(srv interface{}, ctx context.Context, d
	return interceptor(ctx, in, info, handler)
}

var _Console_serviceDesc = grpc.ServiceDesc{
// Console_ServiceDesc is the grpc.ServiceDesc for Console service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Console_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "nakama.console.Console",
	HandlerType: (*ConsoleServer)(nil),
	Methods: []grpc.MethodDesc{
Loading