diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-04-04 02:34:14 +0900 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-04-03 10:34:14 -0700 |
commit | 43e795448f62fa86f3dad7940fc2297c44a6ea9c (patch) | |
tree | aec7f651c2177f9cc02824f014bccd81e96c542a /model | |
parent | 6b61834ab14e9a4e51c29dd2904a1332c327aae6 (diff) | |
download | chat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.tar.gz chat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.tar.bz2 chat-43e795448f62fa86f3dad7940fc2297c44a6ea9c.zip |
APIv4 post /teams/search (#5931)
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 10 | ||||
-rw-r--r-- | model/team_search.go | 35 | ||||
-rw-r--r-- | model/team_search_test.go | 19 |
3 files changed, 64 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index 3d0f19622..0d4c0600e 100644 --- a/model/client4.go +++ b/model/client4.go @@ -842,6 +842,16 @@ func (c *Client4) GetTeamByName(name, etag string) (*Team, *Response) { } } +// SearchTeams returns teams matching the provided search term. +func (c *Client4) SearchTeams(search *TeamSearch) ([]*Team, *Response) { + if r, err := c.DoApiPost(c.GetTeamsRoute()+"/search", search.ToJson()); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return TeamListFromJson(r.Body), BuildResponse(r) + } +} + // 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 { diff --git a/model/team_search.go b/model/team_search.go new file mode 100644 index 000000000..4ab30f96b --- /dev/null +++ b/model/team_search.go @@ -0,0 +1,35 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +type TeamSearch struct { + Term string `json:"term"` +} + +// ToJson convert a TeamSearch to json string +func (c *TeamSearch) ToJson() string { + b, err := json.Marshal(c) + if err != nil { + return "" + } + + return string(b) +} + +// TeamSearchFromJson decodes the input and returns a TeamSearch +func TeamSearchFromJson(data io.Reader) *TeamSearch { + decoder := json.NewDecoder(data) + var cs TeamSearch + err := decoder.Decode(&cs) + if err == nil { + return &cs + } + + return nil +} diff --git a/model/team_search_test.go b/model/team_search_test.go new file mode 100644 index 000000000..996adad43 --- /dev/null +++ b/model/team_search_test.go @@ -0,0 +1,19 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestTeamSearchJson(t *testing.T) { + teamSearch := TeamSearch{Term: NewId()} + json := teamSearch.ToJson() + rteamSearch := ChannelSearchFromJson(strings.NewReader(json)) + + if teamSearch.Term != rteamSearch.Term { + t.Fatal("Terms do not match") + } +} |