Added inventaire import from ISBN
This commit is contained in:
@@ -125,3 +125,27 @@ func TestCallInventaireEdition(t *testing.T) {
|
||||
},
|
||||
result)
|
||||
}
|
||||
|
||||
func TestCallInventaireEditionFromISBN(t *testing.T) {
|
||||
result, err := CallInventaireFromISBN("9782070379248", "fr")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t,
|
||||
&InventaireEditionDetailedSingleResult{
|
||||
Id: "isbn:9782070379248",
|
||||
Title: "Du côté de chez swann",
|
||||
Author: &InventaireAuthorResult{
|
||||
ID: "Q7199",
|
||||
Name: "Marcel Proust",
|
||||
Description: "écrivain, critique et essayiste français",
|
||||
},
|
||||
Description: "roman de Marcel Proust",
|
||||
ISBN: "978-2-07-037924-8",
|
||||
Publisher: "Éditions Gallimard",
|
||||
ReleaseDate: "1988",
|
||||
Image: "https://inventaire.io/img/entities/646a3ef031d6a1adc27cb5f556d2a403a2f525a7",
|
||||
Lang: "fr",
|
||||
},
|
||||
result)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ type InventaireEditionDetailedSingleResult struct {
|
||||
Lang string
|
||||
}
|
||||
|
||||
type ErrorEditionNotFound struct {
|
||||
InventaireId string
|
||||
}
|
||||
|
||||
func (e *ErrorEditionNotFound) Error() string {
|
||||
return fmt.Sprintf("No edition found on inventaire for id %s\n", e.InventaireId)
|
||||
}
|
||||
|
||||
func CallInventaireEdition(inventaireId string, lang string) (InventaireEditionDetailedSingleResult, error) {
|
||||
var result InventaireEditionDetailedSingleResult
|
||||
editionQueryResults, err := callInventaireEditionEntities([]string{inventaireId})
|
||||
@@ -24,7 +32,7 @@ func CallInventaireEdition(inventaireId string, lang string) (InventaireEditionD
|
||||
}
|
||||
var editionQueryResult inventaireEditionQueryEntity
|
||||
if len(editionQueryResults.Entities) < 1 {
|
||||
return result, fmt.Errorf("No edition found on inventaire for id %s", inventaireId)
|
||||
return result, &ErrorEditionNotFound{InventaireId: inventaireId}
|
||||
}
|
||||
|
||||
editionQueryResult = editionQueryResults.Entities[0]
|
||||
|
||||
16
internal/inventaire/inventaireeditionfromisbn.go
Normal file
16
internal/inventaire/inventaireeditionfromisbn.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package inventaire
|
||||
|
||||
import "errors"
|
||||
|
||||
func CallInventaireFromISBN(isbn string, lang string) (*InventaireEditionDetailedSingleResult, error) {
|
||||
inventaireInfo, err := CallInventaireEdition("isbn:"+isbn, lang)
|
||||
if err != nil {
|
||||
if errors.Is(err, &ErrorEditionNotFound{}) {
|
||||
//suppress the not found error, returns nil instead
|
||||
return nil, nil
|
||||
} else {
|
||||
return &inventaireInfo, err
|
||||
}
|
||||
}
|
||||
return &inventaireInfo, err
|
||||
}
|
||||
Reference in New Issue
Block a user