2018-07-14 17:36:17 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// Create implements the creation method via the interface
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Creates a new namespace
|
|
|
|
// @Description Creates a new namespace.
|
|
|
|
// @tags namespace
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param namespace body models.Namespace true "The namespace you want to create."
|
|
|
|
// @Success 200 {object} models.Namespace "The created namespace."
|
|
|
|
// @Failure 400 {object} models.HTTPError "Invalid namespace object provided."
|
|
|
|
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /namespaces [put]
|
2018-07-18 08:56:19 +02:00
|
|
|
func (n *Namespace) Create(doer *User) (err error) {
|
2018-07-14 17:36:17 +02:00
|
|
|
// Check if we have at least a name
|
|
|
|
if n.Name == "" {
|
|
|
|
return ErrNamespaceNameCannotBeEmpty{NamespaceID: 0, UserID: doer.ID}
|
|
|
|
}
|
|
|
|
n.ID = 0 // This would otherwise prevent the creation of new lists after one was created
|
|
|
|
|
|
|
|
// Check if the User exists
|
2018-08-30 19:14:02 +02:00
|
|
|
n.Owner, err = GetUserByID(doer.ID)
|
2018-07-14 17:36:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
n.OwnerID = n.Owner.ID
|
|
|
|
|
|
|
|
// Insert
|
|
|
|
_, err = x.Insert(n)
|
|
|
|
return
|
|
|
|
}
|