2018-07-02 08:54:44 +02:00
|
|
|
package models
|
2018-07-04 08:15:47 +02:00
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Update implements the update method via the interface
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Updates a namespace
|
|
|
|
// @Description Updates a namespace.
|
|
|
|
// @tags namespace
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param id path int true "Namespace ID"
|
|
|
|
// @Param namespace body models.Namespace true "The namespace with updated values you want to update."
|
|
|
|
// @Success 200 {object} models.Namespace "The updated 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 /namespace/{id} [post]
|
2018-07-21 15:17:02 +02:00
|
|
|
func (n *Namespace) Update() (err error) {
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if we have at least a name
|
|
|
|
if n.Name == "" {
|
2018-07-21 15:17:02 +02:00
|
|
|
return ErrNamespaceNameCannotBeEmpty{NamespaceID: n.ID}
|
2018-07-04 08:15:47 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if the namespace exists
|
2018-07-21 15:17:02 +02:00
|
|
|
currentNamespace, err := GetNamespaceByID(n.ID)
|
2018-07-04 08:15:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if the (new) owner exists
|
2018-10-06 18:55:14 +02:00
|
|
|
n.OwnerID = n.Owner.ID
|
2018-07-12 00:30:31 +02:00
|
|
|
if currentNamespace.OwnerID != n.OwnerID {
|
2018-08-30 19:14:02 +02:00
|
|
|
n.Owner, err = GetUserByID(n.OwnerID)
|
2018-07-12 00:30:31 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-07-12 00:09:16 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Do the actual update
|
|
|
|
_, err = x.ID(currentNamespace.ID).Update(n)
|
2018-07-12 00:09:16 +02:00
|
|
|
return
|
2018-07-12 00:37:31 +02:00
|
|
|
}
|