Fixed error when inserting an empty publisher
This commit is contained in:
parent
310d15d078
commit
7e40119014
|
@ -1,15 +1,19 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
||||||
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
||||||
if publisher.ID == 0 {
|
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)
|
_, err = x.Insert(&publisher)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Publisher{}, err
|
return Publisher{}, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_, err = x.ID(publisher.ID).Update(&publisher)
|
_, err = x.ID(publisher.ID).Update(&publisher)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue