From 4551d1f4d928afe6d9d50c582a82615a5625ece8 Mon Sep 17 00:00:00 2001 From: appel_c Date: Thu, 30 Jan 2025 17:15:34 +0100 Subject: [PATCH] refactor(remote-data-service) : add patch to remote-data service, refactored scandataservice to simplify api --- .../src/app/core/remote-data.service.ts | 35 +++++++++++++++++++ .../app/scan-table/scan-table.component.ts | 9 ++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/frontend/bec_atlas/src/app/core/remote-data.service.ts b/frontend/bec_atlas/src/app/core/remote-data.service.ts index 8ea45ae..21cebd8 100644 --- a/frontend/bec_atlas/src/app/core/remote-data.service.ts +++ b/frontend/bec_atlas/src/app/core/remote-data.service.ts @@ -54,6 +54,23 @@ export class RemoteDataService { } ); } + + /** + * Base method for making a PATCH request to the server + * @param path path to the endpoint + * @param payload payload to send + * @param headers additional headers + * @returns response from the server + */ + protected patch(path: string, payload: any, headers: HttpHeaders) { + return this.httpClient.patch( + this.serverSettings.getServerAddress() + path, + payload, + { + headers, + } + ); + } } @Injectable({ @@ -189,4 +206,22 @@ export class ScanCountService extends RemoteDataService { } return this.get('scans/count', filters, headers); } + + /** + * Method for updating the user data for a scan + * @param scanId Unique identifier for the scan + * @param userData User data to update + * @returns response from the server + * @throws HttpErrorResponse if the request fails + * @throws TimeoutError if the request takes too long + */ + updateUserData(scanId: string, userData: ScanUserData) { + let headers = new HttpHeaders(); + headers = headers.set('Content-Type', 'application/json; charset=utf-8'); + return this.post( + 'scans/user_data', + { scan_id: scanId, ...userData }, + headers + ); + } } diff --git a/frontend/bec_atlas/src/app/scan-table/scan-table.component.ts b/frontend/bec_atlas/src/app/scan-table/scan-table.component.ts index 25571bf..872ae4b 100644 --- a/frontend/bec_atlas/src/app/scan-table/scan-table.component.ts +++ b/frontend/bec_atlas/src/app/scan-table/scan-table.component.ts @@ -7,7 +7,7 @@ import { Signal, inject, } from '@angular/core'; -import { ScanCountService, ScanDataService } from '../core/remote-data.service'; +import { ScanDataService } from '../core/remote-data.service'; import { ScanDataResponse } from '../core/model/scan-data'; import { CommonModule } from '@angular/common'; import { MatTableModule } from '@angular/material/table'; @@ -152,7 +152,7 @@ export class ScanTableComponent { loadScanCountResource = resource({ request: () => this.reloadCriteria(), loader: ({ request, abortSignal }): Promise => { - return firstValueFrom(this.scanCount.getScanCount(request.sessionId)); + return firstValueFrom(this.scanData.getScanCount(request.sessionId)); }, }); @@ -182,10 +182,7 @@ export class ScanTableComponent { return data.count; } - constructor( - private scanData: ScanDataService, - private scanCount: ScanCountService - ) { + constructor(private scanData: ScanDataService) { this.tableData = computed(() => this.handleScanData(this.loadScanDataResource.value() || []) );