From e3593d4321a995166427fb2a42bed212f55e6cfe Mon Sep 17 00:00:00 2001 From: ferreo Date: Tue, 30 Jul 2024 02:22:38 +0100 Subject: [PATCH] Fix empties --- handlers/build/queue.go | 12 +++++++++++- handlers/packages/packages.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/handlers/build/queue.go b/handlers/build/queue.go index 4b33886..d3917c1 100644 --- a/handlers/build/queue.go +++ b/handlers/build/queue.go @@ -49,7 +49,17 @@ func Queue(c *fiber.Ctx) error { return finalReturn[i].Source.Name < finalReturn[j].Source.Name }) - result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize] + var result []domain.BuildQueueItem + startIndex := adjustedPageNum * pageSize + endIndex := (adjustedPageNum + 1) * pageSize + if startIndex >= len(finalReturn) { + result = []domain.BuildQueueItem{} + } else { + if endIndex > len(finalReturn) { + endIndex = len(finalReturn) + } + result = finalReturn[startIndex:endIndex] + } response := QueueResponse{ Total: len(finalReturn), diff --git a/handlers/packages/packages.go b/handlers/packages/packages.go index 1ee2d1b..17966d2 100644 --- a/handlers/packages/packages.go +++ b/handlers/packages/packages.go @@ -52,7 +52,17 @@ func Packages(c *fiber.Ctx) error { return finalReturn[i].Name < finalReturn[j].Name }) - result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize] + var result []domain.SourcePackage + startIndex := adjustedPageNum * pageSize + endIndex := (adjustedPageNum + 1) * pageSize + if startIndex >= len(finalReturn) { + result = []domain.SourcePackage{} + } else { + if endIndex > len(finalReturn) { + endIndex = len(finalReturn) + } + result = finalReturn[startIndex:endIndex] + } response := PackagesResponse{ Total: len(finalReturn),