Allow address.country and address.state as company sort fields.
Frontend sends nested address field names for sorting; accept them alongside the existing country and state aliases. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -76,7 +76,7 @@ type SearchForm struct {
|
|||||||
FoundedYearMax *int `query:"founded_year_max" valid:"optional,range(1800|2100)"`
|
FoundedYearMax *int `query:"founded_year_max" valid:"optional,range(1800|2100)"`
|
||||||
Limit *int `query:"limit" valid:"optional,range(1|100)"`
|
Limit *int `query:"limit" valid:"optional,range(1|100)"`
|
||||||
Offset *int `query:"offset" valid:"optional,range(0|1000000)"`
|
Offset *int `query:"offset" valid:"optional,range(0|1000000)"`
|
||||||
SortBy *string `query:"sort_by" valid:"optional,in(name|type|industry|created_at|updated_at|status|employee_count|annual_revenue|email|phone|country|state|language|currency)"`
|
SortBy *string `query:"sort_by" valid:"optional,in(name|type|industry|created_at|updated_at|status|employee_count|annual_revenue|email|phone|country|state|address.country|address.state|language|currency)"`
|
||||||
SortOrder *string `query:"sort_order" valid:"optional,in(asc|desc)"`
|
SortOrder *string `query:"sort_order" valid:"optional,in(asc|desc)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,3 +53,29 @@ func TestHashFilterStable(t *testing.T) {
|
|||||||
t.Fatalf("expected stable non-empty hash, got %q and %q", a, b)
|
t.Fatalf("expected stable non-empty hash, got %q and %q", a, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDocumentSortValueNestedField(t *testing.T) {
|
||||||
|
doc := bson.M{
|
||||||
|
"_id": bson.NewObjectID(),
|
||||||
|
"address": bson.M{
|
||||||
|
"country": "US",
|
||||||
|
"state": "NY",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
country, err := documentSortValue(doc, "address.country")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("address.country: %v", err)
|
||||||
|
}
|
||||||
|
if country != "US" {
|
||||||
|
t.Fatalf("expected US, got %v", country)
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err := documentSortValue(doc, "address.state")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("address.state: %v", err)
|
||||||
|
}
|
||||||
|
if state != "NY" {
|
||||||
|
t.Fatalf("expected NY, got %v", state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user