diff --git a/models/publishers_add_update.go b/models/publishers_add_update.go index 7bd4f18..d942c4c 100644 --- a/models/publishers_add_update.go +++ b/models/publishers_add_update.go @@ -1,15 +1,19 @@ package models +import "fmt" + // AddOrUpdatePublisher adds or updates a publisher from a publisher struct func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) { if publisher.ID == 0 { - if publisher.Name != "" { // Only insert it if the name is not empty + if publisher.Name == "" { // Only insert it if the name is not empty + return Publisher{}, fmt.Errorf("You need at least a name to insert a new publisher") + } + _, err = x.Insert(&publisher) if err != nil { return Publisher{}, err } - } } else { _, err = x.ID(publisher.ID).Update(&publisher)