Inventaire import: manage case where author does not exist
This commit is contained in:
@@ -132,6 +132,27 @@ func TestCallInventaireEdition(t *testing.T) {
|
|||||||
result)
|
result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCalInventaireEditionNoAuthor(t *testing.T) {
|
||||||
|
|
||||||
|
result, err := CallInventaireEdition(getBaseInventaireUrl(), "isbn:9782226487162", "fr")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t,
|
||||||
|
InventaireEditionDetailedSingleResult{
|
||||||
|
Id: "isbn:9782226487162",
|
||||||
|
Title: "Les Yeux de Mona",
|
||||||
|
Author: nil,
|
||||||
|
Description: "",
|
||||||
|
ISBN: "978-2-226-48716-2",
|
||||||
|
Publisher: "éditions Albin Michel",
|
||||||
|
ReleaseDate: "2024-02-01",
|
||||||
|
Image: "https://inventaire.io/img/entities/3ca857913983d694be03dee712bb2af9e2c51747",
|
||||||
|
Lang: "fr",
|
||||||
|
},
|
||||||
|
result)
|
||||||
|
}
|
||||||
|
|
||||||
func TestCallInventaireEditionFromISBN(t *testing.T) {
|
func TestCallInventaireEditionFromISBN(t *testing.T) {
|
||||||
result, err := CallInventaireFromISBN(getBaseInventaireUrl(), "9782070379248", "fr")
|
result, err := CallInventaireFromISBN(getBaseInventaireUrl(), "9782070379248", "fr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -40,18 +40,21 @@ func PostImportBookHandler(ac appcontext.AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveInventaireBookToDb(ac appcontext.AppContext, inventaireEdition inventaire.InventaireEditionDetailedSingleResult, user *model.User) (*model.Book, error) {
|
func saveInventaireBookToDb(ac appcontext.AppContext, inventaireEdition inventaire.InventaireEditionDetailedSingleResult, user *model.User) (*model.Book, error) {
|
||||||
author, err := fetchOrCreateInventaireAuthor(ac, inventaireEdition.Author)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
book := model.Book{
|
book := model.Book{
|
||||||
Title: inventaireEdition.Title,
|
Title: inventaireEdition.Title,
|
||||||
SmallDescription: inventaireEdition.Description,
|
SmallDescription: inventaireEdition.Description,
|
||||||
InventaireID: inventaireEdition.Id,
|
InventaireID: inventaireEdition.Id,
|
||||||
Author: *author,
|
|
||||||
AddedBy: *user,
|
AddedBy: *user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inventaireEdition.Author != nil {
|
||||||
|
author, err := fetchOrCreateInventaireAuthor(ac, inventaireEdition.Author)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
book.Author = *author
|
||||||
|
}
|
||||||
|
|
||||||
if inventaireEdition.Image != "" {
|
if inventaireEdition.Image != "" {
|
||||||
cover, err := fileutils.DownloadFile(ac, inventaireEdition.Image)
|
cover, err := fileutils.DownloadFile(ac, inventaireEdition.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -59,7 +62,7 @@ func saveInventaireBookToDb(ac appcontext.AppContext, inventaireEdition inventai
|
|||||||
}
|
}
|
||||||
book.Cover = cover
|
book.Cover = cover
|
||||||
}
|
}
|
||||||
err = ac.Db.Save(&book).Error
|
err := ac.Db.Save(&book).Error
|
||||||
return &book, err
|
return &book, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user