Map to slice
This commit is contained in:
parent
57f1d0d6af
commit
f4487c0040
@ -3,7 +3,7 @@ package handlers_build
|
||||
import (
|
||||
"brunel/buildqueue"
|
||||
"brunel/domain"
|
||||
"brunel/fastmap"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type QueueResponse struct {
|
||||
Total int `json:"total"`
|
||||
Packages *fastmap.Fastmap[string, domain.BuildQueueItem] `json:"packages"`
|
||||
Packages []domain.BuildQueueItem `json:"packages"`
|
||||
}
|
||||
|
||||
func Queue(c *fiber.Ctx) error {
|
||||
@ -27,7 +27,7 @@ func Queue(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
packs := buildqueue.GetQueue()
|
||||
finalReturn := fastmap.New[string, domain.BuildQueueItem]()
|
||||
finalReturn := make([]domain.BuildQueueItem, 0)
|
||||
|
||||
packs.ForEach(func(k string, source domain.BuildQueueItem) bool {
|
||||
matchesSearch := search == "" || strings.Contains(strings.ToLower(k), search)
|
||||
@ -40,16 +40,19 @@ func Queue(c *fiber.Ctx) error {
|
||||
})
|
||||
|
||||
if matchesFilter && matchesSearch {
|
||||
finalReturn.Set(k, source)
|
||||
finalReturn = append(finalReturn, source)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
finalReturn.StableSortByKey()
|
||||
result := finalReturn.GetPage(adjustedPageNum, pageSize)
|
||||
sort.Slice(finalReturn, func(i, j int) bool {
|
||||
return finalReturn[i].Source.Name < finalReturn[j].Source.Name
|
||||
})
|
||||
|
||||
result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize]
|
||||
|
||||
response := QueueResponse{
|
||||
Total: finalReturn.Len(),
|
||||
Total: len(finalReturn),
|
||||
Packages: result,
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ package handlers_packages
|
||||
|
||||
import (
|
||||
"brunel/domain"
|
||||
"brunel/fastmap"
|
||||
"brunel/packages"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type PackagesResponse struct {
|
||||
Total int `json:"total"`
|
||||
Packages *fastmap.Fastmap[string, domain.SourcePackage] `json:"packages"`
|
||||
Packages []domain.SourcePackage `json:"packages"`
|
||||
}
|
||||
|
||||
func Packages(c *fiber.Ctx) error {
|
||||
@ -28,8 +28,7 @@ func Packages(c *fiber.Ctx) error {
|
||||
|
||||
packs := packages.GetPackages()
|
||||
|
||||
finalReturn := fastmap.New[string, domain.SourcePackage]()
|
||||
|
||||
finalReturn := make([]domain.SourcePackage, 0)
|
||||
packs.ForEach(func(k string, source domain.SourcePackage) bool {
|
||||
matchesFilter := filter == ""
|
||||
matchesSearch := search == "" || strings.Contains(strings.ToLower(k), search)
|
||||
@ -45,15 +44,18 @@ func Packages(c *fiber.Ctx) error {
|
||||
})
|
||||
|
||||
if matchesFilter && matchesSearch {
|
||||
finalReturn.Set(k, source)
|
||||
finalReturn = append(finalReturn, source)
|
||||
}
|
||||
return true
|
||||
})
|
||||
finalReturn.StableSortByKey()
|
||||
result := finalReturn.GetPage(adjustedPageNum, pageSize)
|
||||
sort.Slice(finalReturn, func(i, j int) bool {
|
||||
return finalReturn[i].Name < finalReturn[j].Name
|
||||
})
|
||||
|
||||
result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize]
|
||||
|
||||
response := PackagesResponse{
|
||||
Total: finalReturn.Len(),
|
||||
Total: len(finalReturn),
|
||||
Packages: result,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user