api/models/namespace_update.go

29 lines
602 B
Go
Raw Normal View History

package models
2018-07-04 06:15:47 +00:00
// Update implements the update method via the interface
2018-07-12 21:07:03 +00:00
func (n *Namespace) Update(id int64) (err error) {
// Check if we have at least a name
if n.Name == "" {
2018-07-12 21:07:03 +00:00
return ErrNamespaceNameCannotBeEmpty{NamespaceID: id}
2018-07-04 06:15:47 +00:00
}
n.ID = id
2018-07-04 06:15:47 +00:00
// Check if the namespace exists
currentNamespace, err := GetNamespaceByID(id)
2018-07-04 06:15:47 +00:00
if err != nil {
return
}
// Check if the (new) owner exists
if currentNamespace.OwnerID != n.OwnerID {
2018-07-12 21:07:03 +00:00
n.Owner, _, err = GetUserByID(n.OwnerID)
if err != nil {
return
}
}
// Do the actual update
_, err = x.ID(currentNamespace.ID).Update(n)
return
2018-07-11 22:37:31 +00:00
}