-
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 retrieve file counts by type, access and category #88
Changes from 5 commits
0f55bf3
8b5a429
682e139
babe2d7
3fa47c4
9d7ced6
3ac5ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,46 +4,45 @@ import { Dataset } from '../../domain/models/Dataset'; | |
import { transformVersionResponseToDataset } from './transformers/datasetTransformers'; | ||
|
||
export class DatasetsRepository extends ApiRepository implements IDatasetsRepository { | ||
private readonly resourceName: string = 'datasets'; | ||
|
||
public async getDatasetSummaryFieldNames(): Promise<string[]> { | ||
return this.doGet('/datasets/summaryFieldNames') | ||
return this.doGet(this.buildApiEndpoint(this.resourceName, 'summaryFieldNames')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I like it better in FileRepository where the dataset resource name has this naming this.datasetsResourceName
I think it helps visually seeing which resource is calling, specially because it seems like the resource called is not always the one in the repository name |
||
.then((response) => response.data.data) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} | ||
|
||
public async getPrivateUrlDataset(token: string): Promise<Dataset> { | ||
return this.doGet(`/datasets/privateUrlDatasetVersion/${token}`) | ||
return this.doGet(this.buildApiEndpoint(this.resourceName, `privateUrlDatasetVersion/${token}`)) | ||
.then((response) => transformVersionResponseToDataset(response)) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} | ||
|
||
public async getDataset(datasetId: number | string, datasetVersionId: string): Promise<Dataset> { | ||
let endpoint; | ||
if (typeof datasetId === 'number') { | ||
endpoint = `/datasets/${datasetId}/versions/${datasetVersionId}`; | ||
} else { | ||
endpoint = `/datasets/:persistentId/versions/${datasetVersionId}?persistentId=${datasetId}`; | ||
} | ||
return this.doGet(endpoint, true) | ||
return this.doGet(this.buildApiEndpoint(this.resourceName, `versions/${datasetVersionId}`, datasetId), true) | ||
.then((response) => transformVersionResponseToDataset(response)) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} | ||
|
||
public async getDatasetCitation(datasetId: number, datasetVersionId: string): Promise<string> { | ||
return this.doGet(`/datasets/${datasetId}/versions/${datasetVersionId}/citation`, true) | ||
return this.doGet( | ||
this.buildApiEndpoint(this.resourceName, `versions/${datasetVersionId}/citation`, datasetId), | ||
true, | ||
) | ||
.then((response) => response.data.data.message) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} | ||
|
||
public async getPrivateUrlDatasetCitation(token: string): Promise<string> { | ||
return this.doGet(`/datasets/privateUrlDatasetVersion/${token}/citation`) | ||
return this.doGet(this.buildApiEndpoint(this.resourceName, `privateUrlDatasetVersion/${token}/citation`)) | ||
.then((response) => response.data.data.message) | ||
.catch((error) => { | ||
throw error; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { FileAccessStatus } from './FileCriteria'; | ||
|
||
export interface FileCounts { | ||
total: number; | ||
perContentType: FileContentTypeCount[]; | ||
perAccessStatus: FileAccessStatusCount[]; | ||
perCategoryName: FileCategoryNameCount[]; | ||
} | ||
|
||
export interface FileContentTypeCount { | ||
contentType: string; | ||
count: number; | ||
} | ||
|
||
export interface FileAccessStatusCount { | ||
accessStatus: FileAccessStatus; | ||
count: number; | ||
} | ||
|
||
export interface FileCategoryNameCount { | ||
categoryName: string; | ||
count: number; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase'; | ||
import { IFilesRepository } from '../repositories/IFilesRepository'; | ||
import { DatasetNotNumberedVersion } from '../../../datasets'; | ||
import { FileCounts } from '../models/FileCounts'; | ||
|
||
export class GetDatasetFileCounts implements UseCase<FileCounts> { | ||
private filesRepository: IFilesRepository; | ||
|
||
constructor(filesRepository: IFilesRepository) { | ||
this.filesRepository = filesRepository; | ||
} | ||
|
||
async execute( | ||
datasetId: number | string, | ||
datasetVersionId: string | DatasetNotNumberedVersion = DatasetNotNumberedVersion.LATEST, | ||
): Promise<FileCounts> { | ||
return await this.filesRepository.getDatasetFileCounts(datasetId, datasetVersionId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { AxiosResponse } from 'axios'; | ||
import { | ||
FileCounts, | ||
FileContentTypeCount, | ||
FileCategoryNameCount, | ||
FileAccessStatusCount, | ||
} from '../../../domain/models/FileCounts'; | ||
import { FileAccessStatus } from '../../../domain/models/FileCriteria'; | ||
|
||
export const transformFileCountsResponseToFileCounts = (response: AxiosResponse): FileCounts => { | ||
const fileCountsPayload = response.data.data; | ||
return { | ||
total: fileCountsPayload.total, | ||
perContentType: transformCountsPerContentTypePayload(fileCountsPayload.perContentType), | ||
perAccessStatus: transformCountsPerAccessStatusPayload(fileCountsPayload.perAccessStatus), | ||
perCategoryName: transformCountsPerCategoryNamePayload(fileCountsPayload.perCategoryName), | ||
}; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const transformCountsPerContentTypePayload = (countsPerContentTypePayload: any): FileContentTypeCount[] => { | ||
const fileContentTypeCounts: FileContentTypeCount[] = []; | ||
const fileContentTypeCountKeys = Object.keys(countsPerContentTypePayload); | ||
for (const fileContentTypeCountKey of fileContentTypeCountKeys) { | ||
fileContentTypeCounts.push({ | ||
contentType: fileContentTypeCountKey, | ||
count: countsPerContentTypePayload[fileContentTypeCountKey], | ||
}); | ||
} | ||
return fileContentTypeCounts; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const transformCountsPerCategoryNamePayload = (countsPerCategoryNamePayload: any): FileCategoryNameCount[] => { | ||
const fileCategoryNameCounts: FileCategoryNameCount[] = []; | ||
const fileCategoryNameCountKeys = Object.keys(countsPerCategoryNamePayload); | ||
for (const fileCategoryNameCountKey of fileCategoryNameCountKeys) { | ||
fileCategoryNameCounts.push({ | ||
categoryName: fileCategoryNameCountKey, | ||
count: countsPerCategoryNamePayload[fileCategoryNameCountKey], | ||
}); | ||
} | ||
return fileCategoryNameCounts; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const transformCountsPerAccessStatusPayload = (countsPerAccessStatusPayload: any): FileAccessStatusCount[] => { | ||
const fileAccessStatusCounts: FileAccessStatusCount[] = []; | ||
const fileAccessStatusCountKeys = Object.keys(countsPerAccessStatusPayload); | ||
for (const fileAccessStatusCountKey of fileAccessStatusCountKeys) { | ||
fileAccessStatusCounts.push({ | ||
accessStatus: fileAccessStatusCountKey as FileAccessStatus, | ||
count: countsPerAccessStatusPayload[fileAccessStatusCountKey], | ||
}); | ||
} | ||
return fileAccessStatusCounts; | ||
}; |
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.
love the refactor using this method 👍