Skip to content

Commit 224e23f

Browse files
committed
docs: use cases doc
1 parent 7da8da7 commit 224e23f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { UploadedFileDTO } from '../dtos/UploadedFileDTO'
3+
import { IFilesRepository } from '../repositories/IFilesRepository'
4+
5+
export class ReplaceFile implements UseCase<void> {
6+
private filesRepository: IFilesRepository
7+
8+
constructor(filesRepository: IFilesRepository) {
9+
this.filesRepository = filesRepository
10+
}
11+
12+
/**
13+
* Replaces an existing file.
14+
*
15+
* This method completes the flow initiated by the UploadFile use case, which involves replacing an existing file with a new one just uploaded.
16+
* (https://guides.dataverse.org/en/latest/developers/s3-direct-upload-api.html#replacing-an-existing-file-in-the-dataset)
17+
*
18+
* Note: This use case can be used independently of the UploadFile use case, e.g., supporting scenarios in which the files already exist in S3 or have been uploaded via some out-of-band method.
19+
*
20+
* @param {number} [fileId] - The File identifier.
21+
* @param {UploadedFileDTO} [uploadedFileDTO] - File DTO associated with the uploaded file.
22+
* @returns {Promise<void>} A promise that resolves when the file has been successfully replaced.
23+
* @throws {WriteError} - If there are errors while writing data.
24+
*/
25+
async execute(fileId: number, uploadedFileDTO: UploadedFileDTO): Promise<void> {
26+
await this.filesRepository.replaceFile(fileId, uploadedFileDTO)
27+
}
28+
}

src/files/domain/useCases/UploadFile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export class UploadFile implements UseCase<string> {
1212
* Uploads a file to remote storage and returns the storage identifier.
1313
*
1414
* This use case is based on the Direct Upload API, particularly the first part of the flow, "Requesting Direct Upload of a DataFile".
15-
* To fulfill the flow, you will need to call the AddUploadedFileToDataset Use Case to add the uploaded file to the dataset.
15+
* To fulfill the flow, you could:
16+
* - Call the AddUploadedFilesToDataset Use Case to add the uploaded file to the dataset.
17+
* - Call the ReplaceFile Use Case to replace an existing file with the uploaded one.
1618
* (https://guides.dataverse.org/en/latest/developers/s3-direct-upload-api.html#requesting-direct-upload-of-a-datafile)
1719
*
1820
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers) or a number (for numeric identifiers).

0 commit comments

Comments
 (0)