From 9621132629e8454fe79cb911f57d6f578c023420 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 16 Oct 2018 11:32:50 +0200 Subject: [PATCH] Add ability to set type of the channel over rest request --- sam/docs/README.md | 2 ++ sam/docs/src/spec.json | 4 +++- sam/docs/src/spec/channel.json | 12 ++++++++++++ sam/rest/channel.go | 2 ++ sam/rest/request/channel.go | 10 ++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sam/docs/README.md b/sam/docs/README.md index fea98967a..b163b27c6 100644 --- a/sam/docs/README.md +++ b/sam/docs/README.md @@ -246,6 +246,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 | YES | | topic | string | POST | Subject of Channel | N/A | NO | +| type | string | POST | Channel type | N/A | NO | ## Update channel details @@ -262,6 +263,7 @@ A channel is a representation of a sequence of messages. It has meta data like c | channelID | uint64 | PATH | Channel ID | N/A | YES | | 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 | | archive | bool | POST | Request channel to be archived or unarchived | N/A | NO | | organisationID | uint64 | POST | Move channel to different organisation | N/A | NO | diff --git a/sam/docs/src/spec.json b/sam/docs/src/spec.json index 2a3ffb3bb..af179bd8c 100644 --- a/sam/docs/src/spec.json +++ b/sam/docs/src/spec.json @@ -214,7 +214,8 @@ "parameters": { "post": [ { "type": "string", "name": "name", "required": true, "title": "Name of Channel" }, - { "type": "string", "name": "topic", "required": false, "title": "Subject of Channel" } + { "type": "string", "name": "topic", "required": false, "title": "Subject of Channel" }, + { "type": "string", "name": "type", "required": false, "title": "Channel type" } ] } }, @@ -230,6 +231,7 @@ "post": [ { "type": "string", "name": "name", "required": false, "title": "Name of Channel" }, { "type": "string", "name": "topic", "required": false, "title": "Subject of Channel" }, + { "type": "string", "name": "type", "required": false, "title": "Channel type" }, { "type": "bool", "name": "archive", "required": false, "title": "Request channel to be archived or unarchived" }, { "type": "uint64", "name": "organisationID", "required": false, "title": "Move channel to different organisation" } ] diff --git a/sam/docs/src/spec/channel.json b/sam/docs/src/spec/channel.json index 2bb7c814d..6c88c26cf 100644 --- a/sam/docs/src/spec/channel.json +++ b/sam/docs/src/spec/channel.json @@ -46,6 +46,12 @@ "required": false, "title": "Subject of Channel", "type": "string" + }, + { + "name": "type", + "required": false, + "title": "Channel type", + "type": "string" } ] } @@ -77,6 +83,12 @@ "title": "Subject of Channel", "type": "string" }, + { + "name": "type", + "required": false, + "title": "Channel type", + "type": "string" + }, { "name": "archive", "required": false, diff --git a/sam/rest/channel.go b/sam/rest/channel.go index 26c8fd255..bd68e634e 100644 --- a/sam/rest/channel.go +++ b/sam/rest/channel.go @@ -34,6 +34,7 @@ func (ctrl *Channel) Create(ctx context.Context, r *request.ChannelCreate) (inte channel := &types.Channel{ Name: r.Name, Topic: r.Topic, + Type: types.ChannelType(r.Type), } return ctrl.wrap(ctrl.svc.ch.With(ctx).Create(channel)) @@ -44,6 +45,7 @@ func (ctrl *Channel) Edit(ctx context.Context, r *request.ChannelEdit) (interfac ID: r.ChannelID, Name: r.Name, Topic: r.Topic, + Type: types.ChannelType(r.Type), } return ctrl.wrap(ctrl.svc.ch.With(ctx).Update(channel)) diff --git a/sam/rest/request/channel.go b/sam/rest/request/channel.go index 35596f31e..b39ff4f73 100644 --- a/sam/rest/request/channel.go +++ b/sam/rest/request/channel.go @@ -79,6 +79,7 @@ var _ RequestFiller = NewChannelList() type ChannelCreate struct { Name string Topic string + Type string } func NewChannelCreate() *ChannelCreate { @@ -119,6 +120,10 @@ func (c *ChannelCreate) Fill(r *http.Request) error { c.Topic = val } + if val, ok := post["type"]; ok { + + c.Type = val + } return err } @@ -130,6 +135,7 @@ type ChannelEdit struct { ChannelID uint64 Name string Topic string + Type string Archive bool OrganisationID uint64 } @@ -173,6 +179,10 @@ func (c *ChannelEdit) Fill(r *http.Request) error { c.Topic = val } + if val, ok := post["type"]; ok { + + c.Type = val + } if val, ok := post["archive"]; ok { c.Archive = parseBool(val)