Skip to content

Commit

Permalink
Merge pull request #93 from IQSS/90-file-counts-criteria
Browse files Browse the repository at this point in the history
Get file counts use case with search criteria
  • Loading branch information
kcondon authored Oct 17, 2023
2 parents cf82844 + 14ac106 commit 5866778
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 65 deletions.
54 changes: 42 additions & 12 deletions src/files/domain/models/FileCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
export class FileCriteria {
export class FileSearchCriteria {
constructor(
public readonly orderCriteria: FileOrderCriteria = FileOrderCriteria.NAME_AZ,
public readonly contentType?: string,
public readonly accessStatus?: FileAccessStatus,
public readonly categoryName?: string,
public readonly tabularTagName?: string,
public readonly searchText?: string,
) {}

withOrderCriteria(orderCriteria: FileOrderCriteria): FileCriteria {
return new FileCriteria(orderCriteria, this.contentType, this.accessStatus, this.categoryName);
withContentType(contentType: string | undefined): FileSearchCriteria {
return new FileSearchCriteria(
contentType,
this.accessStatus,
this.categoryName,
this.tabularTagName,
this.searchText,
);
}

withContentType(contentType: string | undefined): FileCriteria {
return new FileCriteria(this.orderCriteria, contentType, this.accessStatus, this.categoryName);
withAccessStatus(accessStatus: FileAccessStatus | undefined): FileSearchCriteria {
return new FileSearchCriteria(
this.contentType,
accessStatus,
this.categoryName,
this.tabularTagName,
this.searchText,
);
}

withAccessStatus(accessStatus: FileAccessStatus | undefined): FileCriteria {
return new FileCriteria(this.orderCriteria, this.contentType, accessStatus, this.categoryName);
withCategoryName(categoryName: string | undefined): FileSearchCriteria {
return new FileSearchCriteria(
this.contentType,
this.accessStatus,
categoryName,
this.tabularTagName,
this.searchText,
);
}

withCategoryName(categoryName: string | undefined): FileCriteria {
return new FileCriteria(this.orderCriteria, this.contentType, this.accessStatus, categoryName);
withTabularTagName(tabularTagName: string | undefined): FileSearchCriteria {
return new FileSearchCriteria(
this.contentType,
this.accessStatus,
this.categoryName,
tabularTagName,
this.searchText,
);
}

withSearchText(searchText: string | undefined): FileCriteria {
return new FileCriteria(this.orderCriteria, this.contentType, this.accessStatus, this.categoryName, searchText);
withSearchText(searchText: string | undefined): FileSearchCriteria {
return new FileSearchCriteria(
this.contentType,
this.accessStatus,
this.categoryName,
this.tabularTagName,
searchText,
);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/files/domain/repositories/IFilesRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { File } from '../models/File';
import { FileDataTable } from '../models/FileDataTable';
import { FileUserPermissions } from '../models/FileUserPermissions';
import { FileCriteria } from '../models/FileCriteria';
import { FileSearchCriteria, FileOrderCriteria } from '../models/FileCriteria';
import { FileCounts } from '../models/FileCounts';
import { FileDownloadSizeMode } from '../models/FileDownloadSizeMode';

Expand All @@ -10,15 +10,17 @@ export interface IFilesRepository {
datasetId: number | string,
datasetVersionId: string,
includeDeaccessioned: boolean,
fileOrderCriteria: FileOrderCriteria,
limit?: number,
offset?: number,
fileCriteria?: FileCriteria,
fileSearchCriteria?: FileSearchCriteria,
): Promise<File[]>;

getDatasetFileCounts(
datasetId: number | string,
datasetVersionId: string,
includeDeaccessioned: boolean,
fileSearchCriteria?: FileSearchCriteria,
): Promise<FileCounts>;

getDatasetFilesTotalDownloadSize(
Expand Down
9 changes: 8 additions & 1 deletion src/files/domain/useCases/GetDatasetFileCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UseCase } from '../../../core/domain/useCases/UseCase';
import { IFilesRepository } from '../repositories/IFilesRepository';
import { DatasetNotNumberedVersion } from '../../../datasets';
import { FileCounts } from '../models/FileCounts';
import { FileSearchCriteria } from '../models/FileCriteria';

export class GetDatasetFileCounts implements UseCase<FileCounts> {
private filesRepository: IFilesRepository;
Expand All @@ -14,7 +15,13 @@ export class GetDatasetFileCounts implements UseCase<FileCounts> {
datasetId: number | string,
datasetVersionId: string | DatasetNotNumberedVersion = DatasetNotNumberedVersion.LATEST,
includeDeaccessioned: boolean = false,
fileSearchCriteria?: FileSearchCriteria,
): Promise<FileCounts> {
return await this.filesRepository.getDatasetFileCounts(datasetId, datasetVersionId, includeDeaccessioned);
return await this.filesRepository.getDatasetFileCounts(
datasetId,
datasetVersionId,
includeDeaccessioned,
fileSearchCriteria,
);
}
}
8 changes: 5 additions & 3 deletions src/files/domain/useCases/GetDatasetFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UseCase } from '../../../core/domain/useCases/UseCase';
import { IFilesRepository } from '../repositories/IFilesRepository';
import { File } from '../models/File';
import { FileCriteria } from '../models/FileCriteria';
import { FileSearchCriteria, FileOrderCriteria } from '../models/FileCriteria';
import { DatasetNotNumberedVersion } from '../../../datasets';

export class GetDatasetFiles implements UseCase<File[]> {
Expand All @@ -17,15 +17,17 @@ export class GetDatasetFiles implements UseCase<File[]> {
includeDeaccessioned: boolean = false,
limit?: number,
offset?: number,
fileCriteria?: FileCriteria,
fileSearchCriteria?: FileSearchCriteria,
fileOrderCriteria: FileOrderCriteria = FileOrderCriteria.NAME_AZ,
): Promise<File[]> {
return await this.filesRepository.getDatasetFiles(
datasetId,
datasetVersionId,
includeDeaccessioned,
fileOrderCriteria,
limit,
offset,
fileCriteria,
fileSearchCriteria,
);
}
}
2 changes: 1 addition & 1 deletion src/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export {

export { File, FileEmbargo, FileChecksum } from './domain/models/File';
export { FileUserPermissions } from './domain/models/FileUserPermissions';
export { FileCriteria, FileOrderCriteria, FileAccessStatus } from './domain/models/FileCriteria';
export { FileSearchCriteria, FileOrderCriteria, FileAccessStatus } from './domain/models/FileCriteria';
export {
FileCounts,
FileContentTypeCount,
Expand Down
47 changes: 29 additions & 18 deletions src/files/infra/repositories/FilesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FileDataTable } from '../../domain/models/FileDataTable';
import { transformDataTablesResponseToDataTables } from './transformers/fileDataTableTransformers';
import { FileUserPermissions } from '../../domain/models/FileUserPermissions';
import { transformFileUserPermissionsResponseToFileUserPermissions } from './transformers/fileUserPermissionsTransformers';
import { FileCriteria } from '../../domain/models/FileCriteria';
import { FileSearchCriteria, FileOrderCriteria } from '../../domain/models/FileCriteria';
import { FileCounts } from '../../domain/models/FileCounts';
import { transformFileCountsResponseToFileCounts } from './transformers/fileCountsTransformers';
import { FileDownloadSizeMode } from '../../domain/models/FileDownloadSizeMode';
Expand All @@ -19,6 +19,7 @@ export interface GetFilesQueryParams {
contentType?: string;
accessStatus?: string;
categoryName?: string;
tabularTagName?: string;
searchText?: string;
}

Expand All @@ -31,21 +32,23 @@ export class FilesRepository extends ApiRepository implements IFilesRepository {
datasetId: number | string,
datasetVersionId: string,
includeDeaccessioned: boolean,
fileOrderCriteria: FileOrderCriteria,
limit?: number,
offset?: number,
fileCriteria?: FileCriteria,
fileSearchCriteria?: FileSearchCriteria,
): Promise<File[]> {
const queryParams: GetFilesQueryParams = {
includeDeaccessioned: includeDeaccessioned,
orderCriteria: fileOrderCriteria.toString(),
};
if (limit !== undefined) {
queryParams.limit = limit;
}
if (offset !== undefined) {
queryParams.offset = offset;
}
if (fileCriteria !== undefined) {
this.applyFileCriteriaToQueryParams(queryParams, fileCriteria);
if (fileSearchCriteria !== undefined) {
this.applyFileSearchCriteriaToQueryParams(queryParams, fileSearchCriteria);
}
return this.doGet(
this.buildApiEndpoint(this.datasetsResourceName, `versions/${datasetVersionId}/files`, datasetId),
Expand All @@ -62,13 +65,18 @@ export class FilesRepository extends ApiRepository implements IFilesRepository {
datasetId: string | number,
datasetVersionId: string,
includeDeaccessioned: boolean,
fileSearchCriteria?: FileSearchCriteria,
): Promise<FileCounts> {
const queryParams: GetFilesQueryParams = {
includeDeaccessioned: includeDeaccessioned,
};
if (fileSearchCriteria !== undefined) {
this.applyFileSearchCriteriaToQueryParams(queryParams, fileSearchCriteria);
}
return this.doGet(
this.buildApiEndpoint(this.datasetsResourceName, `versions/${datasetVersionId}/files/counts`, datasetId),
true,
{
includeDeaccessioned: includeDeaccessioned,
},
queryParams,
)
.then((response) => transformFileCountsResponseToFileCounts(response))
.catch((error) => {
Expand Down Expand Up @@ -118,21 +126,24 @@ export class FilesRepository extends ApiRepository implements IFilesRepository {
});
}

private applyFileCriteriaToQueryParams(queryParams: GetFilesQueryParams, fileCriteria: FileCriteria) {
if (fileCriteria.accessStatus !== undefined) {
queryParams.accessStatus = fileCriteria.accessStatus.toString();
private applyFileSearchCriteriaToQueryParams(
queryParams: GetFilesQueryParams,
fileSearchCriteria: FileSearchCriteria,
) {
if (fileSearchCriteria.accessStatus !== undefined) {
queryParams.accessStatus = fileSearchCriteria.accessStatus.toString();
}
if (fileCriteria.categoryName !== undefined) {
queryParams.categoryName = fileCriteria.categoryName;
if (fileSearchCriteria.categoryName !== undefined) {
queryParams.categoryName = fileSearchCriteria.categoryName;
}
if (fileCriteria.contentType !== undefined) {
queryParams.contentType = fileCriteria.contentType;
if (fileSearchCriteria.tabularTagName !== undefined) {
queryParams.tabularTagName = fileSearchCriteria.tabularTagName;
}
if (fileCriteria.searchText !== undefined) {
queryParams.searchText = fileCriteria.searchText;
if (fileSearchCriteria.contentType !== undefined) {
queryParams.contentType = fileSearchCriteria.contentType;
}
if (fileCriteria.orderCriteria !== undefined) {
queryParams.orderCriteria = fileCriteria.orderCriteria.toString();
if (fileSearchCriteria.searchText !== undefined) {
queryParams.searchText = fileSearchCriteria.searchText;
}
}
}
Loading

0 comments on commit 5866778

Please sign in to comment.