-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add use case to get all datasets previews with pagination #107
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
02f0b3c
Added: GetCollectionDatasetPreviews use case (pending data access logic)
GPortas f0e42bf
Added: DatasetPreview model fields
GPortas 77f7dbc
Added: pagination params to GetCollectionDatasetPreviews use case
GPortas f07f09e
Changed: GetCollectionDatasetPreviews renamed to GetAllDatasetPreviews
GPortas 0e43746
Added: getAllDatasetPreviews repository method (pending IT)
GPortas ff7491c
Added: getAllDatasetPreviews IT (failing). Pending fixes
GPortas 89f3d1d
Fixed: getAllDatasetPreviews IT
GPortas cb8c0ce
Added: IT for getAllDatasetPreviews and datasets creation moved to se…
GPortas 08ef12f
Fixed: reintroduced IT removed by mistake
GPortas ef9b425
Added: pagination unit test case for getAllDatasetPreviews
GPortas 8fbabda
Merge branch 'develop' of github.com:IQSS/dataverse-client-javascript…
GPortas 11e5d7f
Refactor: using payload models for Dataset previews and locks
GPortas 06043ee
Added: DatasetPreviewSubset model to contain both previews and total …
GPortas eef3ed7
Added: IT environment and test tweaks
GPortas 228a37e
fix: race condition solr container
MellyGray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DatasetVersionInfo } from './Dataset'; | ||
|
||
export interface DatasetPreview { | ||
persistentId: string; | ||
title: string; | ||
versionId: number; | ||
versionInfo: DatasetVersionInfo; | ||
citation: string; | ||
description: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { DatasetPreview } from './DatasetPreview'; | ||
|
||
export interface DatasetPreviewSubset { | ||
datasetPreviews: DatasetPreview[]; | ||
totalDatasetCount: number; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase'; | ||
import { IDatasetsRepository } from '../repositories/IDatasetsRepository'; | ||
import { DatasetPreviewSubset } from '../models/DatasetPreviewSubset'; | ||
|
||
export class GetAllDatasetPreviews implements UseCase<DatasetPreviewSubset> { | ||
private datasetsRepository: IDatasetsRepository; | ||
|
||
constructor(datasetsRepository: IDatasetsRepository) { | ||
this.datasetsRepository = datasetsRepository; | ||
} | ||
|
||
async execute(limit?: number, offset?: number): Promise<DatasetPreviewSubset> { | ||
return await this.datasetsRepository.getAllDatasetPreviews(limit, offset); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
src/datasets/infra/repositories/transformers/datasetLocksTransformers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/datasets/infra/repositories/transformers/datasetPreviewsTransformers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { AxiosResponse } from 'axios'; | ||
import { DatasetPreview } from '../../../domain/models/DatasetPreview'; | ||
import { DatasetVersionState } from '../../../domain/models/Dataset'; | ||
import { DatasetPreviewSubset } from '../../../domain/models/DatasetPreviewSubset'; | ||
|
||
export interface DatasetPreviewPayload { | ||
global_id: string; | ||
name: string; | ||
versionId: number; | ||
majorVersion: number; | ||
minorVersion: number; | ||
versionState: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
published_at?: string; | ||
citation: string; | ||
description: string; | ||
} | ||
|
||
export const transformDatasetPreviewsResponseToDatasetPreviewSubset = ( | ||
response: AxiosResponse, | ||
): DatasetPreviewSubset => { | ||
const responseDataPayload = response.data.data; | ||
const datasetPreviewsPayload = responseDataPayload.items; | ||
const datasetPreviews: DatasetPreview[] = []; | ||
datasetPreviewsPayload.forEach(function (datasetPreviewPayload: DatasetPreviewPayload) { | ||
datasetPreviews.push(transformDatasetPreviewPayloadToDatasetPreview(datasetPreviewPayload)); | ||
}); | ||
return { | ||
datasetPreviews: datasetPreviews, | ||
totalDatasetCount: responseDataPayload.total_count, | ||
}; | ||
}; | ||
|
||
const transformDatasetPreviewPayloadToDatasetPreview = ( | ||
datasetPreviewPayload: DatasetPreviewPayload, | ||
): DatasetPreview => { | ||
return { | ||
persistentId: datasetPreviewPayload.global_id, | ||
title: datasetPreviewPayload.name, | ||
versionId: datasetPreviewPayload.versionId, | ||
versionInfo: { | ||
majorNumber: datasetPreviewPayload.majorVersion, | ||
minorNumber: datasetPreviewPayload.minorVersion, | ||
state: datasetPreviewPayload.versionState as DatasetVersionState, | ||
createTime: new Date(datasetPreviewPayload.createdAt), | ||
lastUpdateTime: new Date(datasetPreviewPayload.updatedAt), | ||
...(datasetPreviewPayload.published_at && { releaseTime: new Date(datasetPreviewPayload.published_at) }), | ||
}, | ||
citation: datasetPreviewPayload.citation, | ||
description: datasetPreviewPayload.description, | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I believe that for the sake of consistency within the module,
getDatasetFiles
should also return FilesSubset, including files and the count informationThis would ensure that the module's responses are predictable. Users of the module would then know that if they use some
getAllItems
use case, the response will be paginated and will include both the items and their countI think that the module use cases shouldn't be coupled to the type of API used and how they are implemented, (Native API or Search API) and the module should be consistent even if each API works differently
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.
I agree, but I wouldn't make this change now as I would first extend the files API to return the total files count along with the files to avoid making two API calls per use case call. We can create two new issues for this: Files API extension + files use case extension.
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.