Skip to content

Commit

Permalink
types alocations
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 12, 2024
1 parent 14560a0 commit 3a26dc9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 39 deletions.
45 changes: 40 additions & 5 deletions src/collections/domain/models/CollectionSearchCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { CollectionItemType } from './CollectionItemType'
import { FilterQuery, OrderType, SortType } from './GetCollectionItemsQueryParams'

export enum SortType {
NAME = 'name',
DATE = 'date'
}

export enum OrderType {
ASC = 'asc',
DESC = 'desc'
}

export type FilterQuery = `${string}:${string}`

export class CollectionSearchCriteria {
constructor(
Expand All @@ -11,19 +22,43 @@ export class CollectionSearchCriteria {
) {}

withSearchText(searchText: string | undefined): CollectionSearchCriteria {
return new CollectionSearchCriteria(searchText, this.itemTypes, this.sort, this.order)
return new CollectionSearchCriteria(
searchText,
this.itemTypes,
this.sort,
this.order,
this.filterQueries
)
}

withItemTypes(itemTypes: CollectionItemType[] | undefined): CollectionSearchCriteria {
return new CollectionSearchCriteria(this.searchText, itemTypes, this.sort, this.order)
return new CollectionSearchCriteria(
this.searchText,
itemTypes,
this.sort,
this.order,
this.filterQueries
)
}

withSort(sort: SortType | undefined): CollectionSearchCriteria {
return new CollectionSearchCriteria(this.searchText, this.itemTypes, sort, this.order)
return new CollectionSearchCriteria(
this.searchText,
this.itemTypes,
sort,
this.order,
this.filterQueries
)
}

withOrder(order: OrderType | undefined): CollectionSearchCriteria {
return new CollectionSearchCriteria(this.searchText, this.itemTypes, this.sort, order)
return new CollectionSearchCriteria(
this.searchText,
this.itemTypes,
this.sort,
order,
this.filterQueries
)
}

withFilterQueries(filterQueries: FilterQuery[] | undefined): CollectionSearchCriteria {
Expand Down
23 changes: 0 additions & 23 deletions src/collections/domain/models/GetCollectionItemsQueryParams.ts

This file was deleted.

19 changes: 15 additions & 4 deletions src/collections/infra/repositories/CollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { CollectionFacet } from '../../domain/models/CollectionFacet'
import { CollectionUserPermissions } from '../../domain/models/CollectionUserPermissions'
import { transformCollectionUserPermissionsResponseToCollectionUserPermissions } from './transformers/collectionUserPermissionsTransformers'
import { CollectionItemSubset } from '../../domain/models/CollectionItemSubset'
import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '../../domain/models/CollectionItemType'
import {
GetCollectionItemsQueryParams,
CollectionSearchCriteria,
OrderType,
SortType
} from '../../domain/models/GetCollectionItemsQueryParams'
} from '../../domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '../../domain/models/CollectionItemType'

export interface NewCollectionRequestPayload {
alias: string
Expand Down Expand Up @@ -45,6 +44,18 @@ export interface NewCollectionInputLevelRequestPayload {
required: boolean
}

export enum GetCollectionItemsQueryParams {
QUERY = 'q',
SHOW_FACETS = 'show_facets',
SORT = 'sort',
ORDER = 'order',
SUBTREE = 'subtree',
PER_PAGE = 'per_page',
START = 'start',
TYPE = 'type',
FILTERQUERY = 'fq'
}

export class CollectionsRepository extends ApiRepository implements ICollectionsRepository {
private readonly collectionsResourceName: string = 'dataverses'

Expand Down
2 changes: 1 addition & 1 deletion test/integration/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CollectionType } from '../../../src/collections/domain/models/Collectio
import {
OrderType,
SortType
} from '../../../src/collections/domain/models/GetCollectionItemsQueryParams'
} from '../../../src/collections/domain/models/CollectionSearchCriteria'

describe('CollectionsRepository', () => {
const testCollectionAlias = 'collectionsRepositoryTestCollection'
Expand Down
14 changes: 8 additions & 6 deletions test/unit/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CollectionsRepository } from '../../../src/collections/infra/repositories/CollectionsRepository'
import {
CollectionsRepository,
GetCollectionItemsQueryParams
} from '../../../src/collections/infra/repositories/CollectionsRepository'
import axios from 'axios'
import {
ApiConfig,
Expand Down Expand Up @@ -31,15 +34,14 @@ import {
createCollectionPreviewModel,
createCollectionPreviewPayload
} from '../../testHelpers/collections/collectionPreviewHelper'
import {
GetCollectionItemsQueryParams,
OrderType,
SortType
} from '../../../src/collections/domain/models/GetCollectionItemsQueryParams'
import {
createCollectionItemsFacetsModel,
createCollectionItemsFacetsPayload
} from '../../testHelpers/collections/collectionItemsFacetsHelper'
import {
OrderType,
SortType
} from '../../../src/collections/domain/models/CollectionSearchCriteria'

describe('CollectionsRepository', () => {
const sut: CollectionsRepository = new CollectionsRepository()
Expand Down

0 comments on commit 3a26dc9

Please sign in to comment.