From bc0e6da602ea7561c79f85be06f1cc4430d5a0f7 Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 14 Jul 2018 17:36:17 +0200 Subject: [PATCH] cleanup --- models/namespace_create.go | 21 +++++++++++++++++++ ...mespaces_rights.go => namespace_rights.go} | 0 ...aces_add_update.go => namespace_update.go} | 20 ------------------ 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 models/namespace_create.go rename models/{namespaces_rights.go => namespace_rights.go} (100%) rename models/{namespaces_add_update.go => namespace_update.go} (54%) diff --git a/models/namespace_create.go b/models/namespace_create.go new file mode 100644 index 00000000000..323579f40cf --- /dev/null +++ b/models/namespace_create.go @@ -0,0 +1,21 @@ +package models + +// Create implements the creation method via the interface +func (n *Namespace) Create(doer *User, _ int64) (err error) { + // 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 + n.Owner, _, err = GetUserByID(doer.ID) + if err != nil { + return + } + n.OwnerID = n.Owner.ID + + // Insert + _, err = x.Insert(n) + return +} diff --git a/models/namespaces_rights.go b/models/namespace_rights.go similarity index 100% rename from models/namespaces_rights.go rename to models/namespace_rights.go diff --git a/models/namespaces_add_update.go b/models/namespace_update.go similarity index 54% rename from models/namespaces_add_update.go rename to models/namespace_update.go index 7502061edfa..a5eaa2e0ee2 100644 --- a/models/namespaces_add_update.go +++ b/models/namespace_update.go @@ -1,25 +1,5 @@ package models -// Create implements the creation method via the interface -func (n *Namespace) Create(doer *User, _ int64) (err error) { - // 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 - n.Owner, _, err = GetUserByID(doer.ID) - if err != nil { - return - } - n.OwnerID = n.Owner.ID - - // Insert - _, err = x.Insert(n) - return -} - // Update implements the update method via the interface func (n *Namespace) Update(id int64) (err error) { // Check if we have at least a name