From d96a6c8abc32ed093f9f970cfd729f081f08e715 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Sat, 27 Apr 2019 16:08:02 +0200 Subject: [PATCH] Revert []string=>[]uint64 change for channel members Due to golang's inability do decode uint64 slice from string slice, we're expecting string input for members (for now): https://github.com/golang/go/issues/15624 --- api/messaging/spec.json | 4 ++-- api/messaging/spec/channel.json | 4 ++-- docs/messaging/README.md | 4 ++-- messaging/rest/channel.go | 16 +++++++++++----- messaging/rest/request/channel.go | 10 +++------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/api/messaging/spec.json b/api/messaging/spec.json index 35e9f4fdf..68dfa93c7 100644 --- a/api/messaging/spec.json +++ b/api/messaging/spec.json @@ -179,7 +179,7 @@ "title": "Channel type" }, { - "type": "[]uint64", + "type": "[]string", "name": "members", "required": false, "title": "Initial members of the channel" @@ -386,7 +386,7 @@ "post": [ { "name": "userID", - "type": "[]uint64", + "type": "[]string", "required": false, "title": "User ID" } diff --git a/api/messaging/spec/channel.json b/api/messaging/spec/channel.json index 582f58015..1b7fb5cad 100644 --- a/api/messaging/spec/channel.json +++ b/api/messaging/spec/channel.json @@ -56,7 +56,7 @@ "name": "members", "required": false, "title": "Initial members of the channel", - "type": "[]uint64" + "type": "[]string" } ] } @@ -262,7 +262,7 @@ "name": "userID", "required": false, "title": "User ID", - "type": "[]uint64" + "type": "[]string" } ] } diff --git a/docs/messaging/README.md b/docs/messaging/README.md index 42bfdfc20..6ad241e4f 100644 --- a/docs/messaging/README.md +++ b/docs/messaging/README.md @@ -120,7 +120,7 @@ A channel is a representation of a sequence of messages. It has meta data like c | name | string | POST | Name of Channel | N/A | NO | | topic | string | POST | Subject of Channel | N/A | NO | | type | string | POST | Channel type | N/A | NO | -| members | []uint64 | POST | Initial members of the channel | N/A | NO | +| members | []string | POST | Initial members of the channel | N/A | NO | ## Update channel details @@ -255,7 +255,7 @@ A channel is a representation of a sequence of messages. It has meta data like c | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | | channelID | uint64 | PATH | Channel ID | N/A | YES | -| userID | []uint64 | POST | User ID | N/A | NO | +| userID | []string | POST | User ID | N/A | NO | ## Attach file to channel diff --git a/messaging/rest/channel.go b/messaging/rest/channel.go index 8a6b959ee..ed78f7960 100644 --- a/messaging/rest/channel.go +++ b/messaging/rest/channel.go @@ -33,10 +33,13 @@ func (Channel) New() *Channel { func (ctrl *Channel) Create(ctx context.Context, r *request.ChannelCreate) (interface{}, error) { channel := &types.Channel{ - Name: r.Name, - Topic: r.Topic, - Type: types.ChannelType(r.Type), - Members: r.Members, + Name: r.Name, + Topic: r.Topic, + Type: types.ChannelType(r.Type), + // Due to golang's inability do decode uint64 slice from string slice, we're expecting + // string input for members (for now) + // https://github.com/golang/go/issues/15624 + Members: payload.ParseUInt64s(r.Members), } return ctrl.wrap(ctrl.svc.ch.With(ctx).Create(channel)) @@ -94,7 +97,10 @@ func (ctrl *Channel) Members(ctx context.Context, r *request.ChannelMembers) (in } func (ctrl *Channel) Invite(ctx context.Context, r *request.ChannelInvite) (interface{}, error) { - return ctrl.wrapMemberSet(ctrl.svc.ch.With(ctx).InviteUser(r.ChannelID, r.UserID...)) + // Due to golang's inability do decode uint64 slice from string slice, we're expecting + // string input for members (for now) + // https://github.com/golang/go/issues/15624 + return ctrl.wrapMemberSet(ctrl.svc.ch.With(ctx).InviteUser(r.ChannelID, payload.ParseUInt64s(r.UserID)...)) } func (ctrl *Channel) Join(ctx context.Context, r *request.ChannelJoin) (interface{}, error) { diff --git a/messaging/rest/request/channel.go b/messaging/rest/request/channel.go index 60219b44c..433fcafd3 100644 --- a/messaging/rest/request/channel.go +++ b/messaging/rest/request/channel.go @@ -81,7 +81,7 @@ type ChannelCreate struct { Name string Topic string Type string - Members []uint64 `json:",string"` + Members []string } func NewChannelCreate() *ChannelCreate { @@ -128,8 +128,6 @@ func (cReq *ChannelCreate) Fill(r *http.Request) (err error) { cReq.Type = val } - cReq.Members = parseUInt64A(r.Form["members"]) - return err } @@ -515,8 +513,8 @@ var _ RequestFiller = NewChannelPart() // Channel invite request parameters type ChannelInvite struct { - ChannelID uint64 `json:",string"` - UserID []uint64 `json:",string"` + ChannelID uint64 `json:",string"` + UserID []string } func NewChannelInvite() *ChannelInvite { @@ -552,8 +550,6 @@ func (cReq *ChannelInvite) Fill(r *http.Request) (err error) { cReq.ChannelID = parseUInt64(chi.URLParam(r, "channelID")) - cReq.UserID = parseUInt64A(r.Form["userID"]) - return err }