From d0af931e6e57b78432d5527b6e7b0be36c538144 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Fri, 24 Mar 2017 21:17:46 +0900 Subject: APIv4 put /teams/{team_id}/patch (#5860) --- model/team.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'model/team.go') 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 +} -- cgit v1.2.3-1-g7c22