-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Filter splitting and rendering for related types #1541
Changes from all commits
db24b99
9471718
b089873
d79b226
d851982
4e64f64
c515d1e
38eb4ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,52 @@ func NewFilter() *Filter { | |
} | ||
} | ||
|
||
func (f *Filter) ToMap(mapping *core.DocumentMapping) map[string]any { | ||
return filterObjectToMap(mapping, f.Conditions) | ||
} | ||
|
||
func filterObjectToMap(mapping *core.DocumentMapping, obj map[connor.FilterKey]any) map[string]any { | ||
outmap := make(map[string]any) | ||
if obj == nil { | ||
return nil | ||
} | ||
for k, v := range obj { | ||
switch keyType := k.(type) { | ||
case *PropertyIndex: | ||
|
||
subObj := v.(map[connor.FilterKey]any) | ||
outkey, _ := mapping.TryToFindNameFromIndex(keyType.Index) | ||
if childMapping, ok := tryGetChildMapping(mapping, keyType.Index); !ok { | ||
outmap[outkey] = filterObjectToMap(mapping, subObj) | ||
} else { | ||
outmap[outkey] = filterObjectToMap(childMapping, subObj) | ||
} | ||
|
||
case *Operator: | ||
switch keyType.Operation { | ||
case "_and", "_or": | ||
v := v.([]any) | ||
logicMapEntries := make([]any, len(v)) | ||
for i, item := range v { | ||
itemMap := item.(map[connor.FilterKey]any) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Can this ever not be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did have a whole type checks for all the type casting in this function. But there really isn't a way for them, to not be the respective types, unless there is a notable bug, in which case it should be caught much higher in the call stack. |
||
logicMapEntries[i] = filterObjectToMap(mapping, itemMap) | ||
} | ||
outmap[keyType.Operation] = logicMapEntries | ||
default: | ||
outmap[keyType.Operation] = v | ||
} | ||
} | ||
} | ||
return outmap | ||
} | ||
|
||
func tryGetChildMapping(mapping *core.DocumentMapping, index int) (*core.DocumentMapping, bool) { | ||
if index <= len(mapping.ChildMappings)-1 { | ||
return mapping.ChildMappings[index], true | ||
} | ||
return nil, false | ||
} | ||
|
||
// Limit represents a limit-offset pairing that controls how many | ||
// and which records will be returned from a request. | ||
type Limit struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Does this need a new test as well?