This commit is contained in:
parent
7fba68f812
commit
3d1a710ae0
|
@ -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
|
// 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
|
// Check if we have at least a booktitle when we're inserting a new book
|
||||||
if book.Title == "" {
|
if book.Title == "" && book.ID == 0{
|
||||||
return Book{}, fmt.Errorf("the book should at least have a title")
|
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)
|
_, exists, err = GetPublisherByID(publisherid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Book{}, err
|
return Book{}, err
|
||||||
|
|
|
@ -50,7 +50,7 @@ func BookAddOrUpdate(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have at least a title
|
// 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!"})
|
return c.JSON(http.StatusBadRequest, models.Message{"You need at least a title to insert a new book!"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user