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