2018-11-26 21:17:33 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018 Vikunja and contributors. All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-07-14 18:29:24 +02:00
|
|
|
package models
|
|
|
|
|
2018-12-01 02:59:17 +01:00
|
|
|
import _ "code.vikunja.io/web" // For swaggerdocs generation
|
|
|
|
|
2018-07-14 18:29:24 +02:00
|
|
|
// Update is the handler to create a team
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Updates a team
|
|
|
|
// @Description Updates a team.
|
|
|
|
// @tags team
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2019-01-03 23:22:06 +01:00
|
|
|
// @Security JWTKeyAuth
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Param id path int true "Team ID"
|
|
|
|
// @Param team body models.Team true "The team with updated values you want to update."
|
|
|
|
// @Success 200 {object} models.Team "The updated team."
|
2018-12-01 02:59:17 +01:00
|
|
|
// @Failure 400 {object} code.vikunja.io/web.HTTPError "Invalid team object provided."
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /teams/{id} [post]
|
2018-07-21 15:17:02 +02:00
|
|
|
func (t *Team) Update() (err error) {
|
2018-07-14 18:29:24 +02:00
|
|
|
// Check if we have a name
|
|
|
|
if t.Name == "" {
|
|
|
|
return ErrTeamNameCannotBeEmpty{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the team exists
|
2018-07-21 15:17:02 +02:00
|
|
|
_, err = GetTeamByID(t.ID)
|
2018-07-14 18:29:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-21 15:17:02 +02:00
|
|
|
_, err = x.ID(t.ID).Update(t)
|
2018-07-14 18:29:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the newly updated team
|
2018-07-21 15:17:02 +02:00
|
|
|
*t, err = GetTeamByID(t.ID)
|
2018-07-14 18:29:24 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|