2018-07-14 18:29:24 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @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."
|
|
|
|
// @Failure 400 {object} models.HTTPError "Invalid team object provided."
|
|
|
|
// @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
|
|
|
|
}
|