feat(assist-api): correct response format for autocomplete
This commit is contained in:
parent
5708aa4b39
commit
ab1b5c19ec
2 changed files with 13 additions and 5 deletions
|
|
@ -102,7 +102,10 @@ func (e *handlersImpl) autocomplete(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.log.Debug(context.Background(), "autocomplete request, projectKey: %s, query: %v, response: %v", projectKey, query, resp)
|
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) {
|
func (e *handlersImpl) socketsListByProject(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ type SessionManager interface {
|
||||||
Stop()
|
Stop()
|
||||||
GetByID(projectID, sessionID string) (*SessionData, error)
|
GetByID(projectID, sessionID string) (*SessionData, error)
|
||||||
GetAll(projectID string, filters []*Filter, sort SortOrder, page, limit int) ([]interface{}, int, map[string]map[string]int, 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 {
|
type sessionManagerImpl struct {
|
||||||
|
|
@ -497,7 +497,7 @@ func matchesFilters(session *SessionData, filters []*Filter, counter map[string]
|
||||||
return true
|
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
|
matches := make(map[string]struct{}) // To ensure uniqueness
|
||||||
lowerValue := strings.ToLower(value)
|
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 {
|
for k := range matches {
|
||||||
results = append(results, k)
|
results = append(results, pair{Type: keyName, Value: k})
|
||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue