fix(treasurechest): fix sorting
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m47s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 4m33s

This commit was merged in pull request #96.
This commit is contained in:
2025-05-17 14:43:23 +02:00
parent 5ef27d9b52
commit 70426361ad

View File

@@ -2,6 +2,7 @@ package service
import (
"fmt"
"slices"
"spend-sparrow/db"
"spend-sparrow/log"
@@ -298,6 +299,10 @@ func sortTree(nodes []*types.TreasureChest) []*types.TreasureChest {
}
}
slices.SortFunc(roots, func(a, b *types.TreasureChest) int {
return compareStrings(a.Name, b.Name)
})
for _, root := range roots {
result = append(result, root)
result = append(result, children[root.Id]...)
@@ -305,3 +310,13 @@ func sortTree(nodes []*types.TreasureChest) []*types.TreasureChest {
return result
}
func compareStrings(a, b string) int {
if a == b {
return 0
}
if a < b {
return -1
}
return 1
}