added bookstruct checking when arriving

This commit is contained in:
konrad 2017-11-24 14:40:35 +01:00 committed by kolaente
parent a19650ac3a
commit 9dcac2a5c2
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package models
import "fmt"
/**
::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
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
exists := false
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)
if err != nil {
return Book{}, err