@@ -11,7 +11,11 @@ import { CollectionFacet } from '../../domain/models/CollectionFacet'
1111import { CollectionUserPermissions } from '../../domain/models/CollectionUserPermissions'
1212import { transformCollectionUserPermissionsResponseToCollectionUserPermissions } from './transformers/collectionUserPermissionsTransformers'
1313import { CollectionItemSubset } from '../../domain/models/CollectionItemSubset'
14- import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCriteria'
14+ import {
15+ CollectionSearchCriteria ,
16+ OrderType ,
17+ SortType
18+ } from '../../domain/models/CollectionSearchCriteria'
1519import { CollectionItemType } from '../../domain/models/CollectionItemType'
1620
1721export interface NewCollectionRequestPayload {
@@ -40,12 +44,16 @@ export interface NewCollectionInputLevelRequestPayload {
4044 required : boolean
4145}
4246
43- export interface GetCollectionItemsQueryParams {
44- q : string
45- subtree ?: string
46- per_page ?: number
47- start ?: number
48- type ?: string
47+ export enum GetCollectionItemsQueryParams {
48+ QUERY = 'q' ,
49+ SHOW_FACETS = 'show_facets' ,
50+ SORT = 'sort' ,
51+ ORDER = 'order' ,
52+ SUBTREE = 'subtree' ,
53+ PER_PAGE = 'per_page' ,
54+ START = 'start' ,
55+ TYPE = 'type' ,
56+ FILTERQUERY = 'fq'
4957}
5058
5159export class CollectionsRepository extends ApiRepository implements ICollectionsRepository {
@@ -119,37 +127,30 @@ export class CollectionsRepository extends ApiRepository implements ICollections
119127 offset ?: number ,
120128 collectionSearchCriteria ?: CollectionSearchCriteria
121129 ) : Promise < CollectionItemSubset > {
122- const queryParams : GetCollectionItemsQueryParams = {
123- q : '*'
124- }
130+ const queryParams = new URLSearchParams ( {
131+ [ GetCollectionItemsQueryParams . QUERY ] : '*' ,
132+ [ GetCollectionItemsQueryParams . SHOW_FACETS ] : 'true' ,
133+ [ GetCollectionItemsQueryParams . SORT ] : SortType . DATE ,
134+ [ GetCollectionItemsQueryParams . ORDER ] : OrderType . DESC
135+ } )
136+
125137 if ( collectionId ) {
126- queryParams . subtree = collectionId
138+ queryParams . set ( GetCollectionItemsQueryParams . SUBTREE , collectionId )
127139 }
140+
128141 if ( limit ) {
129- queryParams . per_page = limit
142+ queryParams . set ( GetCollectionItemsQueryParams . PER_PAGE , limit . toString ( ) )
130143 }
144+
131145 if ( offset ) {
132- queryParams . start = offset
146+ queryParams . set ( GetCollectionItemsQueryParams . START , offset . toString ( ) )
133147 }
148+
134149 if ( collectionSearchCriteria ) {
135150 this . applyCollectionSearchCriteriaToQueryParams ( queryParams , collectionSearchCriteria )
136151 }
137152
138- let url = '/search?sort=date&order=desc'
139-
140- if ( collectionSearchCriteria ?. itemTypes ) {
141- const itemTypesQueryString = collectionSearchCriteria . itemTypes
142- . map ( ( itemType : CollectionItemType ) => {
143- const mappedItemType =
144- itemType === CollectionItemType . COLLECTION ? 'dataverse' : itemType . toString ( )
145- return `type=${ mappedItemType } `
146- } )
147- . join ( '&' )
148-
149- url += `&${ itemTypesQueryString } `
150- }
151-
152- return this . doGet ( url , true , queryParams )
153+ return this . doGet ( '/search' , true , queryParams )
153154 . then ( ( response ) => transformCollectionItemsResponseToCollectionItemSubset ( response ) )
154155 . catch ( ( error ) => {
155156 throw error
@@ -201,11 +202,42 @@ export class CollectionsRepository extends ApiRepository implements ICollections
201202 }
202203
203204 private applyCollectionSearchCriteriaToQueryParams (
204- queryParams : GetCollectionItemsQueryParams ,
205+ queryParams : URLSearchParams ,
205206 collectionSearchCriteria : CollectionSearchCriteria
206207 ) {
207208 if ( collectionSearchCriteria . searchText ) {
208- queryParams . q = encodeURIComponent ( collectionSearchCriteria . searchText )
209+ queryParams . set (
210+ GetCollectionItemsQueryParams . QUERY ,
211+ encodeURIComponent ( collectionSearchCriteria . searchText )
212+ )
213+ }
214+
215+ if ( collectionSearchCriteria ?. itemTypes ) {
216+ collectionSearchCriteria . itemTypes . forEach ( ( itemType ) => {
217+ const mappedItemType = itemType === CollectionItemType . COLLECTION ? 'dataverse' : itemType
218+
219+ queryParams . append ( GetCollectionItemsQueryParams . TYPE , mappedItemType )
220+ } )
221+ }
222+
223+ if ( collectionSearchCriteria ?. sort ) {
224+ queryParams . set ( GetCollectionItemsQueryParams . SORT , collectionSearchCriteria . sort )
225+ }
226+
227+ if ( collectionSearchCriteria ?. order ) {
228+ queryParams . set ( GetCollectionItemsQueryParams . ORDER , collectionSearchCriteria . order )
229+ }
230+
231+ if ( collectionSearchCriteria ?. filterQueries ) {
232+ collectionSearchCriteria . filterQueries . forEach ( ( filterQuery ) => {
233+ const [ filterQueryKey , filterQueryValue ] = filterQuery . split ( ':' )
234+
235+ const filterQueryValueWithQuotes = `"${ filterQueryValue } "`
236+
237+ const filterQueryToSet = `${ filterQueryKey } :${ filterQueryValueWithQuotes } `
238+
239+ queryParams . append ( GetCollectionItemsQueryParams . FILTERQUERY , filterQueryToSet )
240+ } )
209241 }
210242 }
211243}
0 commit comments