From 9dcac2a5c2ef9b13350d2e535e669bed36337582 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 24 Nov 2017 14:40:35 +0100 Subject: [PATCH] added bookstruct checking when arriving --- models/books_add_update.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/models/books_add_update.go b/models/books_add_update.go index 199a772..df797ff 100644 --- a/models/books_add_update.go +++ b/models/books_add_update.go @@ -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