Skip to content

Commit

Permalink
feat: add support for result projection in WorksQuery with Elements f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
lsdch committed Jan 14, 2025
1 parent 0c1436d commit 9cee3ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions works_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ type WorksQuery struct {
// Filters on different keys are applied with AND semantic.
// Filters on the same key are applied with OR semantic.
Filters *WorksFilter
// Results projection.
// Restrict the API results to a subset of fields.
// See API docs for available fields
Elements []string
}

func (q WorksQuery) Encode() (values url.Values, err error) {
Expand Down Expand Up @@ -396,5 +400,12 @@ func (q WorksQuery) Encode() (values url.Values, err error) {
filters := q.Filters.Encode()
values.Add("filter", filters)
}

// Projection
if q.Elements != nil {
projection := strings.Join(q.Elements, ",")
values.Add("select", projection)
}

return values, nil
}
10 changes: 10 additions & 0 deletions works_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ func TestWorksQuery_Encode(t *testing.T) {
},
wantErr: false,
},
{
name: "With elements",
query: WorksQuery{
Elements: []string{"title", "abstract", "author"},
},
want: url.Values{
"select": []string{"title,abstract,author"},
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 9cee3ad

Please sign in to comment.