Commit 7ff2532f authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Add console storage get object function.

parent 1d77fcca
Loading
Loading
Loading
Loading
+184 −148

File changed.

Preview size limit exceeded, changes collapsed.

+74 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import (
	"github.com/golang/protobuf/ptypes/empty"
	"github.com/grpc-ecosystem/grpc-gateway/runtime"
	"github.com/grpc-ecosystem/grpc-gateway/utilities"
	"github.com/heroiclabs/nakama/api"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/grpclog"
@@ -483,6 +484,55 @@ func request_Console_GetStatus_0(ctx context.Context, marshaler runtime.Marshale

}

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

	var (
		val string
		ok  bool
		err error
		_   = err
	)

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

	protoReq.Collection, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "collection", err)
	}

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

	protoReq.Key, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "key", err)
	}

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

	protoReq.UserId, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_id", err)
	}

	msg, err := client.GetStorage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

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 metadata runtime.ServerMetadata
@@ -1218,6 +1268,26 @@ func RegisterConsoleHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl

	})

	mux.Handle("GET", pattern_Console_GetStorage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Console_GetStorage_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Console_GetStorage_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("GET", pattern_Console_GetWalletLedger_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -1514,6 +1584,8 @@ var (

	pattern_Console_GetStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "console", "status"}, ""))

	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_ListStorage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "console", "storage"}, ""))
@@ -1574,6 +1646,8 @@ var (

	forward_Console_GetStatus_0 = runtime.ForwardResponseMessage

	forward_Console_GetStorage_0 = runtime.ForwardResponseMessage

	forward_Console_GetWalletLedger_0 = runtime.ForwardResponseMessage

	forward_Console_ListStorage_0 = runtime.ForwardResponseMessage
+5 −0
Original line number Diff line number Diff line
@@ -155,6 +155,11 @@ service Console {
    option (google.api.http).get = "/v2/console/status";
  }

  // Get a storage object.
  rpc GetStorage (nakama.api.ReadStorageObjectId) returns (nakama.api.StorageObject) {
    option (google.api.http).get = "/v2/console/storage/{collection}/{key}/{user_id}";
  }

  // Get a list of the user's wallet transactions.
  rpc GetWalletLedger (AccountId) returns (WalletLedgerList) {
    option (google.api.http).get = "/v2/console/account/{id}/wallet";
+38 −0
Original line number Diff line number Diff line
@@ -647,6 +647,44 @@
      }
    },
    "/v2/console/storage/{collection}/{key}/{user_id}": {
      "get": {
        "summary": "Get a storage object.",
        "operationId": "GetStorage",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/apiStorageObject"
            }
          }
        },
        "parameters": [
          {
            "name": "collection",
            "description": "The collection which stores the object.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "key",
            "description": "The key of the object within the collection.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "user_id",
            "description": "The user owner of the object.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "Console"
        ]
      },
      "delete": {
        "summary": "Delete a storage object.",
        "operationId": "DeleteStorageObject",
+23 −0
Original line number Diff line number Diff line
@@ -769,6 +769,29 @@ export const NakamaApi = (configuration: ConfigurationParameters = {

      return this.doFetch(urlPath, "DELETE", queryParams, _body, options)
    },
    /** Get a storage object. */
    getStorage(collection: string, key: string, userId: string, options: any = {}): Promise<ApiStorageObject> {
      if (collection === null || collection === undefined) {
        throw new Error("'collection' is a required parameter but is null or undefined.");
      }
      if (key === null || key === undefined) {
        throw new Error("'key' is a required parameter but is null or undefined.");
      }
      if (userId === null || userId === undefined) {
        throw new Error("'userId' is a required parameter but is null or undefined.");
      }
      const urlPath = "/v2/console/storage/{collection}/{key}/{user_id}"
         .replace("{collection}", encodeURIComponent(String(collection)))
         .replace("{key}", encodeURIComponent(String(key)))
         .replace("{user_id}", encodeURIComponent(String(userId)));

      const queryParams = {
      } as any;

      let _body = null;

      return this.doFetch(urlPath, "GET", queryParams, _body, options)
    },
    /** Write a new storage object or replace an existing one. */
    writeStorageObject(collection: string, key: string, userId: string, options: any = {}): Promise<ApiStorageObjectAck> {
      if (collection === null || collection === undefined) {
Loading