From 3d1a710ae086365498704bbd3d78802dcaee6ace Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 29 Nov 2017 15:59:34 +0100 Subject: [PATCH] Fixed: When updating a book, no title is needed --- models/books_add_update.go | 6 ++---- routes/api/v1/books_add_update.go | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/models/books_add_update.go b/models/books_add_update.go index d298810..8240dad 100644 --- a/models/books_add_update.go +++ b/models/books_add_update.go @@ -20,8 +20,8 @@ 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 == "" { + // Check if we have at least a booktitle when we're inserting a new book + if book.Title == "" && book.ID == 0{ return Book{}, fmt.Errorf("the book should at least have a title") } @@ -35,8 +35,6 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) { } } - fmt.Println(publisherid) - _, exists, err = GetPublisherByID(publisherid) if err != nil { return Book{}, err diff --git a/routes/api/v1/books_add_update.go b/routes/api/v1/books_add_update.go index 80e311c..4bb3814 100644 --- a/routes/api/v1/books_add_update.go +++ b/routes/api/v1/books_add_update.go @@ -50,7 +50,7 @@ func BookAddOrUpdate(c echo.Context) error { } // Check if we have at least a title - if datBook.Title == "" { + if datBook.Title == "" && datBook.ID == 0 { return c.JSON(http.StatusBadRequest, models.Message{"You need at least a title to insert a new book!"}) }