From 9feceb9b3c61007d5fc6fcdfca7da23d30703894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20K=C3=BCng?= Date: Mon, 16 Feb 2026 14:36:26 +0100 Subject: [PATCH] fix(back-end): file error handling --- .gitea/workflows/cicd.yaml | 10 ----- .../calculator/calculator-page.component.html | 1 + .../calculator/calculator-page.component.ts | 37 +++++++++++++++++++ .../upload-form/upload-form.component.ts | 3 ++ .../services/quote-estimator.service.ts | 7 ++++ 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/cicd.yaml b/.gitea/workflows/cicd.yaml index 386d3cd..d5d5f80 100644 --- a/.gitea/workflows/cicd.yaml +++ b/.gitea/workflows/cicd.yaml @@ -21,16 +21,6 @@ jobs: java-version: '21' distribution: 'temurin' - - name: Cache Gradle - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: gradle-${{ runner.os }}-${{ hashFiles('backend/gradle/wrapper/gradle-wrapper.properties', 'backend/**/*.gradle*', 'backend/gradle.properties') }} - restore-keys: | - gradle-${{ runner.os }}- - - name: Run Tests with Gradle run: | cd backend diff --git a/frontend/src/app/features/calculator/calculator-page.component.html b/frontend/src/app/features/calculator/calculator-page.component.html index 7a3385c..57fd25e 100644 --- a/frontend/src/app/features/calculator/calculator-page.component.html +++ b/frontend/src/app/features/calculator/calculator-page.component.html @@ -37,6 +37,7 @@ [loading]="loading()" [uploadProgress]="uploadProgress()" (submitRequest)="onCalculate($event)" + (itemRemoved)="onItemRemoved($event)" > diff --git a/frontend/src/app/features/calculator/calculator-page.component.ts b/frontend/src/app/features/calculator/calculator-page.component.ts index f40412b..fb0f064 100644 --- a/frontend/src/app/features/calculator/calculator-page.component.ts +++ b/frontend/src/app/features/calculator/calculator-page.component.ts @@ -224,6 +224,43 @@ export class CalculatorPageComponent implements OnInit { } } + onItemRemoved(event: {index: number, id?: string}) { + // 1. Update local result if exists to keep UI in sync + const currentRes = this.result(); + if (currentRes) { + const updatedItems = [...currentRes.items]; + updatedItems.splice(event.index, 1); + + // Recalculate totals locally for immediate feedback + let totalTime = 0; + let totalWeight = 0; + let itemsPrice = 0; + + updatedItems.forEach(i => { + totalTime += i.unitTime * i.quantity; + totalWeight += i.unitWeight * i.quantity; + itemsPrice += i.unitPrice * i.quantity; + }); + + this.result.set({ + ...currentRes, + items: updatedItems, + totalPrice: Math.round((itemsPrice + currentRes.setupCost) * 100) / 100, + totalTimeHours: Math.floor(totalTime / 3600), + totalTimeMinutes: Math.ceil((totalTime % 3600) / 60), + totalWeight: Math.ceil(totalWeight) + }); + } + + // 2. Delete from backend if ID exists + if (event.id && currentRes?.sessionId) { + this.estimator.deleteLineItem(currentRes.sessionId, event.id).subscribe({ + next: () => console.log('Line item deleted from backend'), + error: (err) => console.error('Failed to delete line item', err) + }); + } + } + onSubmitOrder(orderData: any) { console.log('Order Submitted:', orderData); this.orderSuccess.set(true); diff --git a/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts b/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts index d407b69..e980214 100644 --- a/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts +++ b/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts @@ -30,6 +30,7 @@ export class UploadFormComponent implements OnInit { loading = input(false); uploadProgress = input(0); submitRequest = output(); + itemRemoved = output<{index: number, id?: string}>(); private estimator = inject(QuoteEstimatorService); private fb = inject(FormBuilder); @@ -252,6 +253,7 @@ export class UploadFormComponent implements OnInit { } removeItem(index: number) { + const itemToRemove = this.items()[index]; this.items.update(current => { const updated = [...current]; const removed = updated.splice(index, 1)[0]; @@ -260,6 +262,7 @@ export class UploadFormComponent implements OnInit { } return updated; }); + this.itemRemoved.emit({ index, id: itemToRemove.id }); } setFiles(files: File[], colors?: string[]) { diff --git a/frontend/src/app/features/calculator/services/quote-estimator.service.ts b/frontend/src/app/features/calculator/services/quote-estimator.service.ts index 35c8cdf..e8cfa4b 100644 --- a/frontend/src/app/features/calculator/services/quote-estimator.service.ts +++ b/frontend/src/app/features/calculator/services/quote-estimator.service.ts @@ -139,6 +139,13 @@ export class QuoteEstimatorService { return this.http.patch(`${environment.apiUrl}/api/quote-sessions/line-items/${lineItemId}`, changes, { headers }); } + deleteLineItem(sessionId: string, lineItemId: string): Observable { + const headers: any = {}; + // @ts-ignore + if (environment.basicAuth) headers['Authorization'] = 'Basic ' + btoa(environment.basicAuth); + return this.http.delete(`${environment.apiUrl}/api/quote-sessions/${sessionId}/line-items/${lineItemId}`, { headers }); + } + createOrder(sessionId: string, orderDetails: any): Observable { const headers: any = {}; // @ts-ignore