chore: cleanup namespace creation

This commit is contained in:
kolaente 2022-03-06 17:08:58 +01:00
parent 9d816205da
commit b60c69c5a8
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -603,20 +603,17 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int
// @Failure 500 {object} models.Message "Internal error" // @Failure 500 {object} models.Message "Internal error"
// @Router /namespaces [put] // @Router /namespaces [put]
func (n *Namespace) Create(s *xorm.Session, a web.Auth) (err error) { func (n *Namespace) Create(s *xorm.Session, a web.Auth) (err error) {
// Check if we have at least a name // Check if we have at least a title
if n.Title == "" { if n.Title == "" {
return ErrNamespaceNameCannotBeEmpty{NamespaceID: 0, UserID: a.GetID()} return ErrNamespaceNameCannotBeEmpty{NamespaceID: 0, UserID: a.GetID()}
} }
n.ID = 0 // This would otherwise prevent the creation of new lists after one was created
// Check if the User exists
n.Owner, err = user.GetUserByID(s, a.GetID()) n.Owner, err = user.GetUserByID(s, a.GetID())
if err != nil { if err != nil {
return return
} }
n.OwnerID = n.Owner.ID n.OwnerID = n.Owner.ID
// Insert
if _, err = s.Insert(n); err != nil { if _, err = s.Insert(n); err != nil {
return err return err
} }