From 6c7d8f8d44d607d01e26d67eb47153fbf62f8e8d Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 16 Dec 2020 15:34:51 +0200 Subject: [PATCH] bulk delete endpoint --- apps/red-ui/src/app/dialogs/dialog.service.ts | 7 +-- .../api/fileManagementController.service.ts | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/apps/red-ui/src/app/dialogs/dialog.service.ts b/apps/red-ui/src/app/dialogs/dialog.service.ts index 38bf820e7..e24cfe30b 100644 --- a/apps/red-ui/src/app/dialogs/dialog.service.ts +++ b/apps/red-ui/src/app/dialogs/dialog.service.ts @@ -48,11 +48,8 @@ export class DialogService { ref.afterClosed().subscribe((result) => { if (result) { - const promises = fileIds - .map((fileId) => this._appStateService.getFileById(projectId, fileId)) - .map((file) => this._fileManagementControllerService.deleteFile(file.projectId, file.fileId).toPromise()); - - Promise.all(promises) + const deleteFilesPromise = this._fileManagementControllerService.deleteFiles(fileIds, projectId).toPromise(); + deleteFilesPromise .then(async () => { await this._appStateService.reloadActiveProjectFiles(); if (cb) cb(); diff --git a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts index 8700e169d..c7efca00d 100644 --- a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts +++ b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts @@ -103,6 +103,57 @@ export class FileManagementControllerService { ); } + /** + * Deletes a a list of files for a given projectId + * None + * @param body fileIds + * @param projectId projectId + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public deleteFiles(body: Array, projectId: string, observe?: 'body', reportProgress?: boolean): Observable; + public deleteFiles(body: Array, projectId: string, observe?: 'response', reportProgress?: boolean): Observable>; + public deleteFiles(body: Array, projectId: string, observe?: 'events', reportProgress?: boolean): Observable>; + public deleteFiles(body: Array, projectId: string, observe: any = 'body', reportProgress: boolean = false): Observable { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling deleteFiles.'); + } + + if (projectId === null || projectId === undefined) { + throw new Error('Required parameter projectId was null or undefined when calling deleteFiles.'); + } + + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = []; + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + // to determine the Content-Type header + const consumes: string[] = ['application/json']; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + headers = headers.set('Content-Type', httpContentTypeSelected); + } + + return this.httpClient.request('post', `${this.basePath}/delete/${encodeURIComponent(String(projectId))}`, { + body: body, + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + }); + } + /** * Returns a downloadable byte stream of the annotated file with the specified fileId * Use the optional \"inline\" request parameter to select, if this downloadAnnotated will be opened in the browser.