fix(treasurechest): fix sorting #96

Merged
tim merged 1 commits from fix-sort into prod 2025-05-17 12:48:18 +00:00

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
}