Fixed error when inserting an empty item
This commit is contained in:
parent
547b44d608
commit
97ebfc0207
|
@ -1,17 +1,21 @@
|
|||
package models
|
||||
|
||||
import "fmt"
|
||||
|
||||
// AddOrUpdateItem adds or updates a item from a item struct
|
||||
func AddOrUpdateItem(item Item) (newItem Item, err error) {
|
||||
// save the quantity for later use
|
||||
qty := item.Quantity
|
||||
|
||||
if item.ID == 0 {
|
||||
if item.Title != "" { // Only insert it if the title is not empty
|
||||
_, err = x.Insert(&item)
|
||||
if item.Title == "" { // Only insert it if the title is not empty
|
||||
return Item{}, fmt.Errorf("You need at least a title to create an item")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return Item{}, err
|
||||
}
|
||||
_, err = x.Insert(&item)
|
||||
|
||||
if err != nil {
|
||||
return Item{}, err
|
||||
}
|
||||
} else {
|
||||
_, err = x.ID(item.ID).Update(&item)
|
||||
|
|
Loading…
Reference in New Issue