Inventaire edition query: fixed results not sorted
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package inventaire
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -70,18 +69,14 @@ func TestCallInventaireEdition_TestOffset(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, 3, len(result.Results))
|
||||
sortedResults := result.Results
|
||||
sort.Slice(sortedResults, func(i, j int) bool {
|
||||
return sortedResults[i].Id > sortedResults[j].Id
|
||||
})
|
||||
|
||||
assert.Equal(t,
|
||||
InventaireEditionResultBook{
|
||||
Id: "isbn:9782072525216",
|
||||
Id: "isbn:9782070138098",
|
||||
Title: "La théorie de l'information",
|
||||
ISBN: "978-2-07-252521-6",
|
||||
ReleaseDate: "",
|
||||
Image: "https://inventaire.io/img/entities/fac578440d9bf7afc7f4c5698aa618b8a4d80d21",
|
||||
ISBN: "978-2-07-013809-8",
|
||||
Publisher: "Éditions Gallimard",
|
||||
ReleaseDate: "2012",
|
||||
Image: "https://inventaire.io/img/entities/a7b9d05c041b98e98c2f429e11cb2b424d78223b",
|
||||
Lang: "fr",
|
||||
},
|
||||
result.Results[0])
|
||||
@@ -97,12 +92,11 @@ func TestCallInventaireEdition_TestOffset(t *testing.T) {
|
||||
result.Results[1])
|
||||
assert.Equal(t,
|
||||
InventaireEditionResultBook{
|
||||
Id: "isbn:9782070138098",
|
||||
Id: "isbn:9782072525216",
|
||||
Title: "La théorie de l'information",
|
||||
ISBN: "978-2-07-013809-8",
|
||||
Publisher: "Éditions Gallimard",
|
||||
ReleaseDate: "2012",
|
||||
Image: "https://inventaire.io/img/entities/a7b9d05c041b98e98c2f429e11cb2b424d78223b",
|
||||
ISBN: "978-2-07-252521-6",
|
||||
ReleaseDate: "",
|
||||
Image: "https://inventaire.io/img/entities/fac578440d9bf7afc7f4c5698aa618b8a4d80d21",
|
||||
Lang: "fr",
|
||||
},
|
||||
result.Results[2])
|
||||
|
||||
@@ -3,6 +3,7 @@ package inventaire
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/callapiutils"
|
||||
@@ -131,6 +132,7 @@ func CallInventaireEdition(inventaireId string, lang string, limit int, offset i
|
||||
return queryResult, err
|
||||
}
|
||||
queryResult.Count = int64(len(uris.Uris))
|
||||
sort.Strings(uris.Uris)
|
||||
limitedUris := uris.Uris
|
||||
if limit != 0 {
|
||||
l := len(uris.Uris)
|
||||
@@ -144,7 +146,12 @@ func CallInventaireEdition(inventaireId string, lang string, limit int, offset i
|
||||
return queryResult, err
|
||||
}
|
||||
|
||||
for _, entity := range editionEntities.Entities {
|
||||
sortedEntities := editionEntities.Entities
|
||||
sort.Slice(sortedEntities, func(i, j int) bool {
|
||||
return sortedEntities[i].Uri < sortedEntities[j].Uri
|
||||
})
|
||||
|
||||
for _, entity := range sortedEntities {
|
||||
publisher := ""
|
||||
if entity.EditionId != "" {
|
||||
publisher, err = callInventairePublisherGetName(entity.EditionId, lang)
|
||||
|
||||
Reference in New Issue
Block a user