Commit 159b0251 authored by Mo Firouz's avatar Mo Firouz Committed by Andrei Mihu
Browse files

Refactor accounts and users. Add notification proto definition. (#159)

parent 75ed7b8c
Loading
Loading
Loading
Loading
+413 −178

File changed.

Preview size limit exceeded, changes collapsed.

+100 −0
Original line number Diff line number Diff line
@@ -256,6 +256,23 @@ func request_Nakama_DeleteFriends_0(ctx context.Context, marshaler runtime.Marsh

}

var (
	filter_Nakama_DeleteNotifications_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)

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

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

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

}

func request_Nakama_GetAccount_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq empty.Empty
	var metadata runtime.ServerMetadata
@@ -436,6 +453,23 @@ func request_Nakama_ListFriends_0(ctx context.Context, marshaler runtime.Marshal

}

var (
	filter_Nakama_ListNotifications_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)

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

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

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

}

var (
	filter_Nakama_RpcFunc_0 = &utilities.DoubleArray{Encoding: map[string]int{"payload": 0, "id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
)
@@ -989,6 +1023,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("DELETE", pattern_Nakama_DeleteNotifications_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		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_Nakama_DeleteNotifications_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

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

	})

	mux.Handle("GET", pattern_Nakama_GetAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -1337,6 +1400,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("GET", pattern_Nakama_ListNotifications_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		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_Nakama_ListNotifications_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

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

	})

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

	pattern_Nakama_DeleteFriends_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "friend"}, ""))

	pattern_Nakama_DeleteNotifications_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "notification"}, ""))

	pattern_Nakama_GetAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "account"}, ""))

	pattern_Nakama_GetUsers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "user"}, ""))
@@ -1677,6 +1771,8 @@ var (

	pattern_Nakama_ListFriends_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "friend"}, ""))

	pattern_Nakama_ListNotifications_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "notification"}, ""))

	pattern_Nakama_RpcFunc_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "rpc", "id"}, ""))

	pattern_Nakama_RpcFunc_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "rpc", "id"}, ""))
@@ -1721,6 +1817,8 @@ var (

	forward_Nakama_DeleteFriends_0 = runtime.ForwardResponseMessage

	forward_Nakama_DeleteNotifications_0 = runtime.ForwardResponseMessage

	forward_Nakama_GetAccount_0 = runtime.ForwardResponseMessage

	forward_Nakama_GetUsers_0 = runtime.ForwardResponseMessage
@@ -1745,6 +1843,8 @@ var (

	forward_Nakama_ListFriends_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListNotifications_0 = runtime.ForwardResponseMessage

	forward_Nakama_RpcFunc_0 = runtime.ForwardResponseMessage

	forward_Nakama_RpcFunc_1 = runtime.ForwardResponseMessage
+54 −4
Original line number Diff line number Diff line
@@ -166,6 +166,11 @@ service Nakama {
    option (google.api.http).delete = "/v2/friend";
  }

  // Delete one or more users by ID or username.
  rpc DeleteNotifications (DeleteNotificationsRequest) returns (google.protobuf.Empty) {
    option (google.api.http).delete = "/v2/notification";
  }

  // Fetch the current user's account.
  rpc GetAccount (google.protobuf.Empty) returns (Account) {
    option (google.api.http).get = "/v2/account";
@@ -250,6 +255,11 @@ service Nakama {
    option (google.api.http).get = "/v2/friend";
  }

  // Fetch list of notifications.
  rpc ListNotifications (ListNotificationsRequest) returns (NotificationList) {
    option (google.api.http).get = "/v2/notification";
  }

  // Execute a Lua function on the server.
  rpc RpcFunc (Rpc) returns (Rpc) {
    option (google.api.http) = {
@@ -535,6 +545,12 @@ message DeleteFriendsRequest {
  repeated string usernames = 2;
}

// Delete one or more notifications for the current user.
message DeleteNotificationsRequest {
  // The id of notifications.
  repeated string ids = 1;
}

// A friend of a user.
message Friend {
  // The friendship status.
@@ -557,6 +573,12 @@ message Friend {
  int32 state = 2; // one of "Friend.State".
}

// A collection of zero or more friends of the user.
message Friends {
  // The Friend objects.
  repeated Friend friends = 1;
}

// Fetch a batch of zero or more users from the server.
message GetUsersRequest {
  // The account id of a user.
@@ -617,10 +639,38 @@ message LinkFacebookRequest {
  google.protobuf.BoolValue import = 4;
}

// A collection of zero or more friends of the user.
message Friends {
  // The Friend objects.
  repeated Friend friends = 1;
// Fetch a list of unexpired notifications.
message ListNotificationsRequest {
  // Max number of notifications to list. Between 1 and 100.
  int64 limit = 1;
  // Use this cursor to paginate notifications. Cache this to catch up to new notifications. The value of this comes from NotificationList.cacheable_cursor.
  string cacheable_cursor = 2;
}

// A notification in the server.
message Notification {
  // ID of the Notification.
  string id = 1;
  // Subject of the notification.
  string subject = 2;
  // Content of the notification in JSON.
  string content = 3;
  // Category code for this notification.
  int64 code = 4;
  // ID of the sender, if a user. Otherwise 'null'.
  string sender_id = 5;
  // The UNIX time when the notification was created.
  google.protobuf.Timestamp create_time = 6;
  // True if this notification was persisted to the database.
  bool persistent = 7;
}

// A collection of zero or more notifications.
message NotificationList {
  // Collection of notifications.
  repeated Notification notifications = 1;
  // Use this cursor to paginate notifications. Cache this to catch up to new notifications.
  string cacheable_cursor = 2;
}

// Execute an Lua function on the server.
+103 −0
Original line number Diff line number Diff line
@@ -763,6 +763,55 @@
        ]
      }
    },
    "/v2/notification": {
      "get": {
        "summary": "Fetch list of notifications.",
        "operationId": "ListNotifications",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/apiNotificationList"
            }
          }
        },
        "parameters": [
          {
            "name": "limit",
            "description": "Max number of notifications to list. Between 1 and 100.",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "int64"
          },
          {
            "name": "cacheable_cursor",
            "description": "Use this cursor to paginate notifications. Cache this to catch up to new notifications. The value of this comes from NotificationList.cacheable_cursor.",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Nakama"
        ]
      },
      "delete": {
        "summary": "Delete one or more users by ID or username.",
        "operationId": "DeleteNotifications",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/protobufEmpty"
            }
          }
        },
        "tags": [
          "Nakama"
        ]
      }
    },
    "/v2/rpc/{id}": {
      "get": {
        "summary": "Execute a Lua function on the server.",
@@ -1153,6 +1202,60 @@
      },
      "description": "A collection of zero or more groups."
    },
    "apiNotification": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "ID of the Notification."
        },
        "subject": {
          "type": "string",
          "description": "Subject of the notification."
        },
        "content": {
          "type": "string",
          "description": "Content of the notification in JSON."
        },
        "code": {
          "type": "string",
          "format": "int64",
          "description": "Category code for this notification."
        },
        "sender_id": {
          "type": "string",
          "description": "ID of the sender, if a user. Otherwise 'null'."
        },
        "create_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the notification was created."
        },
        "persistent": {
          "type": "boolean",
          "format": "boolean",
          "description": "True if this notification was persisted to the database."
        }
      },
      "description": "A notification in the server."
    },
    "apiNotificationList": {
      "type": "object",
      "properties": {
        "notifications": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/apiNotification"
          },
          "description": "Collection of notifications."
        },
        "cacheable_cursor": {
          "type": "string",
          "description": "Use this cursor to paginate notifications. Cache this to catch up to new notifications."
        }
      },
      "description": "A collection of zero or more notifications."
    },
    "apiRpc": {
      "type": "object",
      "properties": {
+1 −1
Original line number Diff line number Diff line
@@ -9,5 +9,5 @@ import "github.com/gobuffalo/packr"
// Go binary. You can use the "packr clean" command to clean up this,
// and any other packr generated files.
func init() {
	packr.PackJSONBytes("./sql", "20180103142001_initial_schema.sql", "\"H4sIAAAAAAAA/6RWXZObNhR996+4sw8NpKztOMk0k20zQzBOmDg4BZx0nzwyXINmQaKSsON2+t87Amzjj/X2Y5/W0tG59x6de8XgeQ+eg8PLraBppmA0fPEGogzBJw+kIGBXKuNC9qDGTWmMTGICFUtQgMoQ7JLEGe52LPiKQlLOYNQfgqEBN+3WjXmnKba8goJsgXEFlURQGZWwojkCfo+xVEAZxLwoc0pYjLChKqvjtCx9zXHfcvClIpQBgZiXW+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