From 914a2b39e18dd6664239cee2d35655a80159034e Mon Sep 17 00:00:00 2001 From: Sjoerd Siebinga Date: Wed, 1 Nov 2023 13:59:43 +0100 Subject: [PATCH] fix(nde): last page calculation error with hydra paging --- ikuzo/service/x/nde/dataset.go | 2 +- ikuzo/service/x/nde/dataset_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ikuzo/service/x/nde/dataset.go b/ikuzo/service/x/nde/dataset.go index 5a9e548c..89b0562f 100644 --- a/ikuzo/service/x/nde/dataset.go +++ b/ikuzo/service/x/nde/dataset.go @@ -117,7 +117,7 @@ func (hv *HydraView) setPager() { hv.First = map[string]string{"@id": hv.hydraPage(1)} next := hv.currentPage + 1 - totalPages := int(hv.TotalItems / hydraObjectPerPage) + totalPages := int(hv.TotalItems/hydraObjectPerPage) + 1 if next <= totalPages { hv.Next = map[string]string{"@id": hv.hydraPage(next)} } diff --git a/ikuzo/service/x/nde/dataset_test.go b/ikuzo/service/x/nde/dataset_test.go index 536d5e61..56bf3ea2 100644 --- a/ikuzo/service/x/nde/dataset_test.go +++ b/ikuzo/service/x/nde/dataset_test.go @@ -52,7 +52,7 @@ func TestHydraView_setPager(t *testing.T) { Type: hydraType, First: firstPage, Next: map[string]string{"@id": "/catalog?page=2"}, - Last: map[string]string{"@id": "/catalog?page=14"}, + Last: map[string]string{"@id": "/catalog?page=15"}, baseID: baseID, TotalItems: 7012, currentPage: 1, @@ -71,7 +71,7 @@ func TestHydraView_setPager(t *testing.T) { Type: hydraType, First: map[string]string{"@id": "/catalog?page=1"}, Next: map[string]string{"@id": "/catalog?page=5"}, - Last: map[string]string{"@id": "/catalog?page=14"}, + Last: map[string]string{"@id": "/catalog?page=15"}, baseID: baseID, TotalItems: 7012, currentPage: 4, @@ -83,17 +83,17 @@ func TestHydraView_setPager(t *testing.T) { Type: hydraType, baseID: baseID, total: 7012, - currentPage: 13, + currentPage: 14, }, &HydraView{ - ID: "/catalog?page=13", + ID: "/catalog?page=14", Type: hydraType, First: map[string]string{"@id": "/catalog?page=1"}, - Next: map[string]string{"@id": "/catalog?page=14"}, - Last: map[string]string{"@id": "/catalog?page=14"}, + Next: map[string]string{"@id": "/catalog?page=15"}, + Last: map[string]string{"@id": "/catalog?page=15"}, baseID: baseID, TotalItems: 7012, - currentPage: 13, + currentPage: 14, }, }, }