2018-07-14 17:34:59 +02:00
|
|
|
package models
|
|
|
|
|
2018-07-14 17:37:46 +02:00
|
|
|
// Create is the handler to create a team
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Creates a new team
|
|
|
|
// @Description Creates a new team in a given namespace. The user needs write-access to the namespace.
|
|
|
|
// @tags team
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param team body models.Team true "The team you want to create."
|
|
|
|
// @Success 200 {object} models.Team "The created team."
|
|
|
|
// @Failure 400 {object} models.HTTPError "Invalid team object provided."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /teams [put]
|
2018-07-18 08:56:19 +02:00
|
|
|
func (t *Team) Create(doer *User) (err error) {
|
2018-07-14 17:34:59 +02:00
|
|
|
// Check if we have a name
|
|
|
|
if t.Name == "" {
|
|
|
|
return ErrTeamNameCannotBeEmpty{}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.CreatedByID = doer.ID
|
2018-07-14 18:29:24 +02:00
|
|
|
t.CreatedBy = *doer
|
2018-07-14 17:34:59 +02:00
|
|
|
|
|
|
|
_, err = x.Insert(t)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-14 18:29:24 +02:00
|
|
|
// Insert the current user as member and admin
|
2018-07-26 09:53:32 +02:00
|
|
|
tm := TeamMember{TeamID: t.ID, UserID: doer.ID, Admin: true}
|
2018-07-18 08:56:19 +02:00
|
|
|
err = tm.Create(doer)
|
2018-07-14 17:34:59 +02:00
|
|
|
return
|
|
|
|
}
|