Nested folders: Fix API response ordering when fetching subfolders (#67258)

* Nested folders: Fix ordering when getting subfolders

* Update endpoint swagger description

* Modify test
This commit is contained in:
Sofia Papagiannaki
2023-04-27 17:24:47 +03:00
committed by GitHub
parent 7c5210a915
commit 893bf08dcf
5 changed files with 28 additions and 23 deletions

View File

@@ -239,10 +239,10 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
sql := strings.Builder{}
args := make([]interface{}, 0, 2)
if q.UID == "" {
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=?"))
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC"))
args = append(args, q.OrgID)
} else {
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid=? AND org_id=?"))
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid=? AND org_id=? ORDER BY title ASC"))
args = append(args, q.UID, q.OrgID)
}

View File

@@ -3,6 +3,7 @@ package folderimpl
import (
"context"
"fmt"
"sort"
"testing"
"github.com/google/go-cmp/cmp"
@@ -544,6 +545,7 @@ func TestIntegrationGetChildren(t *testing.T) {
require.NoError(t, err)
treeLeaves := CreateLeaves(t, folderStore, parent, 8)
sort.Strings(treeLeaves)
t.Cleanup(func() {
for _, uid := range treeLeaves {
@@ -768,9 +770,10 @@ func CreateLeaves(t *testing.T, store *sqlStore, parent *folder.Folder, num int)
leaves := make([]string, 0)
for i := 0; i < num; i++ {
uid := util.GenerateShortUID()
f, err := store.Create(context.Background(), folder.CreateFolderCommand{
Title: fmt.Sprintf("folder-%d", i),
UID: util.GenerateShortUID(),
Title: fmt.Sprintf("folder-%s", uid),
UID: uid,
OrgID: parent.OrgID,
ParentUID: parent.UID,
})