1
0

implemented namespace creation via interface method

This commit is contained in:
konrad
2018-07-12 00:09:16 +02:00
committed by kolaente
parent 4734a0a6a6
commit 0aa84e653f
5 changed files with 44 additions and 3 deletions

View File

@ -305,3 +305,19 @@ func IsErrUserDoesNotHaveWriteAccessToNamespace(err error) bool {
func (err ErrUserDoesNotHaveWriteAccessToNamespace) Error() string {
return fmt.Sprintf("You need to have write access to this namespace to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
}
// ErrNamespaceNameCannotBeEmpty represents an error, where a namespace name is empty.
type ErrNamespaceNameCannotBeEmpty struct {
NamespaceID int64
UserID int64
}
// IsErrNamespaceNameCannotBeEmpty checks if an error is a ErrNamespaceDoesNotExist.
func IsErrNamespaceNameCannotBeEmpty(err error) bool {
_, ok := err.(ErrNamespaceNameCannotBeEmpty)
return ok
}
func (err ErrNamespaceNameCannotBeEmpty) Error() string {
return fmt.Sprintf("Namespace name cannot be emtpy [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
}

View File

@ -30,3 +30,21 @@ func CreateOrUpdateNamespace(namespace *Namespace) (err error) {
return
}
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}
}
// 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
}