vikunja-api/models/namespace_update.go

28 lines
584 B
Go
Raw Normal View History

package models
2018-07-04 08:15:47 +02:00
// Update implements the update method via the interface
func (n *Namespace) Update() (err error) {
// Check if we have at least a name
if n.Name == "" {
return ErrNamespaceNameCannotBeEmpty{NamespaceID: n.ID}
2018-07-04 08:15:47 +02:00
}
// Check if the namespace exists
currentNamespace, err := GetNamespaceByID(n.ID)
2018-07-04 08:15:47 +02:00
if err != nil {
return
}
// Check if the (new) owner exists
if currentNamespace.OwnerID != n.OwnerID {
2018-08-30 19:14:02 +02: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-12 00:37:31 +02:00
}