added bookstruct checking when arriving
This commit is contained in:
parent
a19650ac3a
commit
9dcac2a5c2
|
@ -1,5 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
::USAGE::
|
::USAGE::
|
||||||
|
|
||||||
|
@ -18,6 +20,11 @@ sie in die Datenbank eingetragen und mit dem Buch verknüpft.
|
||||||
// AddOrUpdateBook adds a new book or updates an existing one, it takes a book struct with author and publisher. Inserts them if they don't already exist
|
// AddOrUpdateBook adds a new book or updates an existing one, it takes a book struct with author and publisher. Inserts them if they don't already exist
|
||||||
func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||||
|
|
||||||
|
// Check if we have at least a booktitle
|
||||||
|
if book.Title == "" {
|
||||||
|
return Book{}, fmt.Errorf("the book should at least have a title")
|
||||||
|
}
|
||||||
|
|
||||||
// Take Publisher, check if it exists. If not, insert it
|
// Take Publisher, check if it exists. If not, insert it
|
||||||
exists := false
|
exists := false
|
||||||
publisherid := book.Publisher
|
publisherid := book.Publisher
|
||||||
|
@ -28,8 +35,6 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check for empty values, should have at least a title. If no publisher is given (aka ID=0 & Name=""), don't insert an empty one.
|
|
||||||
|
|
||||||
_, exists, err = GetPublisherByID(publisherid)
|
_, exists, err = GetPublisherByID(publisherid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Book{}, err
|
return Book{}, err
|
||||||
|
|
Loading…
Reference in New Issue