diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-03-08 01:30:33 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-03-07 19:30:33 -0500 |
commit | 19ec4c42989df53279a1e7fe8dc997244ffbb20c (patch) | |
tree | 305febf622536ec03b1ef7190b7657be5a244811 /model | |
parent | fa75e0e7c45dfd7b72b9fa56dfb4b0ca1496c81c (diff) | |
download | chat-19ec4c42989df53279a1e7fe8dc997244ffbb20c.tar.gz chat-19ec4c42989df53279a1e7fe8dc997244ffbb20c.tar.bz2 chat-19ec4c42989df53279a1e7fe8dc997244ffbb20c.zip |
add team exists endpoint for APIv4 (#5517)
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 10 | ||||
-rw-r--r-- | model/utils.go | 21 |
2 files changed, 31 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index d3bb6534d..34176bfb3 100644 --- a/model/client4.go +++ b/model/client4.go @@ -600,6 +600,16 @@ func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response) { } } +// TeamExists returns true or false if the team exist or not. +func (c *Client4) TeamExists(name, etag string) (bool, *Response) { + if r, err := c.DoApiGet(c.GetTeamByNameRoute(name)+"/exists", etag); err != nil { + return false, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return MapBoolFromJson(r.Body)["exists"], BuildResponse(r) + } +} + // GetTeamsForUser returns a list of teams a user is on. Must be logged in as the user // or be a system administrator. func (c *Client4) GetTeamsForUser(userId, etag string) ([]*Team, *Response) { diff --git a/model/utils.go b/model/utils.go index 08809a47f..8ae45b140 100644 --- a/model/utils.go +++ b/model/utils.go @@ -156,6 +156,15 @@ func MapToJson(objmap map[string]string) string { } } +// MapToJson converts a map to a json string +func MapBoolToJson(objmap map[string]bool) string { + if b, err := json.Marshal(objmap); err != nil { + return "" + } else { + return string(b) + } +} + // MapFromJson will decode the key/value pair map func MapFromJson(data io.Reader) map[string]string { decoder := json.NewDecoder(data) @@ -168,6 +177,18 @@ func MapFromJson(data io.Reader) map[string]string { } } +// MapFromJson will decode the key/value pair map +func MapBoolFromJson(data io.Reader) map[string]bool { + decoder := json.NewDecoder(data) + + var objmap map[string]bool + if err := decoder.Decode(&objmap); err != nil { + return make(map[string]bool) + } else { + return objmap + } +} + func ArrayToJson(objmap []string) string { if b, err := json.Marshal(objmap); err != nil { return "" |