From ab1b5c19ec4133ee86c89a0d7b60623717e136fd Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 15 Apr 2025 16:22:08 +0200 Subject: [PATCH] feat(assist-api): correct response format for autocomplete --- ee/backend/pkg/assist/api/handlers.go | 5 ++++- ee/backend/pkg/sessionmanager/manager.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ee/backend/pkg/assist/api/handlers.go b/ee/backend/pkg/assist/api/handlers.go index 63a52fb09..277701d69 100644 --- a/ee/backend/pkg/assist/api/handlers.go +++ b/ee/backend/pkg/assist/api/handlers.go @@ -102,7 +102,10 @@ func (e *handlersImpl) autocomplete(w http.ResponseWriter, r *http.Request) { return } e.log.Debug(context.Background(), "autocomplete request, projectKey: %s, query: %v, response: %v", projectKey, query, resp) - e.responser.ResponseWithJSON(e.log, r.Context(), w, resp, startTime, r.URL.Path, bodySize) + response := map[string]interface{}{ + "data": resp, + } + e.responser.ResponseWithJSON(e.log, r.Context(), w, response, startTime, r.URL.Path, bodySize) } func (e *handlersImpl) socketsListByProject(w http.ResponseWriter, r *http.Request) { diff --git a/ee/backend/pkg/sessionmanager/manager.go b/ee/backend/pkg/sessionmanager/manager.go index edc5b6fc3..36d43042d 100644 --- a/ee/backend/pkg/sessionmanager/manager.go +++ b/ee/backend/pkg/sessionmanager/manager.go @@ -45,7 +45,7 @@ type SessionManager interface { Stop() GetByID(projectID, sessionID string) (*SessionData, error) GetAll(projectID string, filters []*Filter, sort SortOrder, page, limit int) ([]interface{}, int, map[string]map[string]int, error) - Autocomplete(projectID string, key FilterType, value string) ([]string, error) + Autocomplete(projectID string, key FilterType, value string) ([]interface{}, error) } type sessionManagerImpl struct { @@ -497,7 +497,7 @@ func matchesFilters(session *SessionData, filters []*Filter, counter map[string] return true } -func (sm *sessionManagerImpl) Autocomplete(projectID string, key FilterType, value string) ([]string, error) { +func (sm *sessionManagerImpl) Autocomplete(projectID string, key FilterType, value string) ([]interface{}, error) { matches := make(map[string]struct{}) // To ensure uniqueness lowerValue := strings.ToLower(value) @@ -550,9 +550,14 @@ func (sm *sessionManagerImpl) Autocomplete(projectID string, key FilterType, val } } - results := make([]string, 0, len(matches)) + results := make([]interface{}, 0, len(matches)) + keyName := strings.ToUpper(string(key)) + type pair struct { + Type string `json:"type"` + Value string `json:"value"` + } for k := range matches { - results = append(results, k) + results = append(results, pair{Type: keyName, Value: k}) } return results, nil }