feat(assist-api): adapted body request parser to current chalice worker schema
This commit is contained in:
parent
f25575a0a8
commit
bcb3b407e8
2 changed files with 27 additions and 24 deletions
|
|
@ -16,17 +16,24 @@ type Query struct {
|
|||
}
|
||||
|
||||
type Filter struct {
|
||||
Type string `json:"type"`
|
||||
Value []string `json:"value"`
|
||||
Value []string `json:"values"`
|
||||
Operator string `json:"operator"` // is|contains
|
||||
Source string `json:"source"` // for metadata only
|
||||
}
|
||||
|
||||
type Pagination struct {
|
||||
Limit int `json:"limit"`
|
||||
Page int `json:"page"`
|
||||
}
|
||||
|
||||
type Sort struct {
|
||||
Key string `json:"key"` // useless
|
||||
Order string `json:"order"` // [ASC|DESC]
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Filters []Filter `json:"filters"`
|
||||
Order string `json:"order"` // sort.order [asc|desc]
|
||||
Limit int `json:"limit"` // pagination.limit
|
||||
Page int `json:"page"` // pagination.page
|
||||
Filters map[string]Filter `json:"filter"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
Sort Sort `json:"sort"`
|
||||
}
|
||||
|
||||
type assistImpl struct {
|
||||
|
|
@ -102,19 +109,18 @@ func (a *assistImpl) GetAll(projectKey string, request *Request) (interface{}, e
|
|||
return nil, fmt.Errorf("failed to get project by key: %s", err)
|
||||
}
|
||||
order := sessionmanager.Asc
|
||||
if request.Order == "desc" {
|
||||
if request.Sort.Order == "DESC" {
|
||||
order = sessionmanager.Desc
|
||||
}
|
||||
filters := make([]*sessionmanager.Filter, 0, len(request.Filters))
|
||||
for _, f := range request.Filters {
|
||||
for name, f := range request.Filters {
|
||||
filters = append(filters, &sessionmanager.Filter{
|
||||
Type: sessionmanager.FilterType(f.Type),
|
||||
Type: sessionmanager.FilterType(name),
|
||||
Value: f.Value,
|
||||
Operator: f.Operator == "is",
|
||||
Source: f.Source,
|
||||
})
|
||||
}
|
||||
return a.sessions.GetAll(strconv.Itoa(int(project.ProjectID)), filters, order, request.Page, request.Limit)
|
||||
return a.sessions.GetAll(strconv.Itoa(int(project.ProjectID)), filters, order, request.Pagination.Page, request.Pagination.Limit)
|
||||
}
|
||||
|
||||
func (a *assistImpl) GetByID(projectKey, sessionID string, filters *Request) (interface{}, error) {
|
||||
|
|
|
|||
|
|
@ -329,6 +329,9 @@ func (sm *sessionManagerImpl) updateSessions() {
|
|||
|
||||
sm.mutex.RLock()
|
||||
toAdd := make([]string, 0, len(updatedSessIDs))
|
||||
if updatedSessIDs == nil {
|
||||
updatedSessIDs = make(map[string]struct{})
|
||||
}
|
||||
for sessID, _ := range sessIDs {
|
||||
if _, exists := sm.cache[sessID]; !exists {
|
||||
updatedSessIDs[sessID] = struct{}{} // Add to updated sessions if not in cache
|
||||
|
|
@ -442,12 +445,10 @@ func matchesFilters(session *SessionData, filters []*Filter) bool {
|
|||
if session.UserCity != nil {
|
||||
value = *session.UserCity
|
||||
}
|
||||
case Metadata:
|
||||
if session.Metadata != nil {
|
||||
value = (*session.Metadata)[filter.Source]
|
||||
}
|
||||
default:
|
||||
return false // Unknown filter type
|
||||
if val, ok := (*session.Metadata)[string(filter.Type)]; ok {
|
||||
value = val
|
||||
}
|
||||
}
|
||||
|
||||
for _, filterValue := range filter.Value {
|
||||
|
|
@ -503,14 +504,10 @@ func (sm *sessionManagerImpl) Autocomplete(projectID string, key FilterType, val
|
|||
if session.UserCity != nil {
|
||||
fieldValue = *session.UserCity
|
||||
}
|
||||
case Metadata:
|
||||
if session.Metadata != nil {
|
||||
if v, ok := (*session.Metadata)[string(key)]; ok {
|
||||
fieldValue = v
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown filter type: %s", key)
|
||||
if v, ok := (*session.Metadata)[string(key)]; ok {
|
||||
fieldValue = v
|
||||
}
|
||||
}
|
||||
|
||||
if fieldValue != "" && strings.Contains(strings.ToLower(fieldValue), lowerValue) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue