Fixed error when inserting an empty publisher

This commit is contained in:
konrad 2018-01-16 14:28:02 +01:00 committed by kolaente
parent 310d15d078
commit 7e40119014
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 2 deletions

View File

@ -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)