summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-24 21:17:46 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-03-24 08:17:46 -0400
commitd0af931e6e57b78432d5527b6e7b0be36c538144 (patch)
tree7196ec5e627fe27b539f982df4374e2d2d381f14 /model
parent4c1eb7ff5575be07b8410e76da4cdaa964c2ef91 (diff)
downloadchat-d0af931e6e57b78432d5527b6e7b0be36c538144.tar.gz
chat-d0af931e6e57b78432d5527b6e7b0be36c538144.tar.bz2
chat-d0af931e6e57b78432d5527b6e7b0be36c538144.zip
APIv4 put /teams/{team_id}/patch (#5860)
Diffstat (limited to 'model')
-rw-r--r--model/client4.go10
-rw-r--r--model/team.go50
2 files changed, 60 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 31b754bd3..214c31865 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -781,6 +781,16 @@ func (c *Client4) UpdateTeam(team *Team) (*Team, *Response) {
}
}
+// PatchTeam partially updates a team. Any missing fields are not updated.
+func (c *Client4) PatchTeam(teamId string, patch *TeamPatch) (*Team, *Response) {
+ if r, err := c.DoApiPut(c.GetTeamRoute(teamId)+"/patch", patch.ToJson()); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return TeamFromJson(r.Body), BuildResponse(r)
+ }
+}
+
// GetTeamMembers returns team members based on the provided team id string.
func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag string) ([]*TeamMember, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
diff --git a/model/team.go b/model/team.go
index 99444bc5e..458f71e95 100644
--- a/model/team.go
+++ b/model/team.go
@@ -41,6 +41,14 @@ type Team struct {
AllowOpenInvite bool `json:"allow_open_invite"`
}
+type TeamPatch struct {
+ DisplayName *string `json:"display_name"`
+ Description *string `json:"description"`
+ CompanyName *string `json:"company_name"`
+ InviteId *string `json:"invite_id"`
+ AllowOpenInvite *bool `json:"allow_open_invite"`
+}
+
type Invites struct {
Invites []map[string]string `json:"invites"`
}
@@ -278,3 +286,45 @@ func (o *Team) SanitizeForNotLoggedIn() {
o.InviteId = ""
}
}
+
+func (t *Team) Patch(patch *TeamPatch) {
+ if patch.DisplayName != nil {
+ t.DisplayName = *patch.DisplayName
+ }
+
+ if patch.Description != nil {
+ t.Description = *patch.Description
+ }
+
+ if patch.CompanyName != nil {
+ t.CompanyName = *patch.CompanyName
+ }
+
+ if patch.InviteId != nil {
+ t.InviteId = *patch.InviteId
+ }
+
+ if patch.AllowOpenInvite != nil {
+ t.AllowOpenInvite = *patch.AllowOpenInvite
+ }
+}
+
+func (t *TeamPatch) ToJson() string {
+ b, err := json.Marshal(t)
+ if err != nil {
+ return ""
+ }
+
+ return string(b)
+}
+
+func TeamPatchFromJson(data io.Reader) *TeamPatch {
+ decoder := json.NewDecoder(data)
+ var team TeamPatch
+ err := decoder.Decode(&team)
+ if err != nil {
+ return nil
+ }
+
+ return &team
+}