fix(back-end): file error handling
This commit is contained in:
@@ -21,16 +21,6 @@ jobs:
|
|||||||
java-version: '21'
|
java-version: '21'
|
||||||
distribution: 'temurin'
|
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
|
- name: Run Tests with Gradle
|
||||||
run: |
|
run: |
|
||||||
cd backend
|
cd backend
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
[loading]="loading()"
|
[loading]="loading()"
|
||||||
[uploadProgress]="uploadProgress()"
|
[uploadProgress]="uploadProgress()"
|
||||||
(submitRequest)="onCalculate($event)"
|
(submitRequest)="onCalculate($event)"
|
||||||
|
(itemRemoved)="onItemRemoved($event)"
|
||||||
></app-upload-form>
|
></app-upload-form>
|
||||||
</app-card>
|
</app-card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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) {
|
onSubmitOrder(orderData: any) {
|
||||||
console.log('Order Submitted:', orderData);
|
console.log('Order Submitted:', orderData);
|
||||||
this.orderSuccess.set(true);
|
this.orderSuccess.set(true);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export class UploadFormComponent implements OnInit {
|
|||||||
loading = input<boolean>(false);
|
loading = input<boolean>(false);
|
||||||
uploadProgress = input<number>(0);
|
uploadProgress = input<number>(0);
|
||||||
submitRequest = output<QuoteRequest>();
|
submitRequest = output<QuoteRequest>();
|
||||||
|
itemRemoved = output<{index: number, id?: string}>();
|
||||||
|
|
||||||
private estimator = inject(QuoteEstimatorService);
|
private estimator = inject(QuoteEstimatorService);
|
||||||
private fb = inject(FormBuilder);
|
private fb = inject(FormBuilder);
|
||||||
@@ -252,6 +253,7 @@ export class UploadFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeItem(index: number) {
|
removeItem(index: number) {
|
||||||
|
const itemToRemove = this.items()[index];
|
||||||
this.items.update(current => {
|
this.items.update(current => {
|
||||||
const updated = [...current];
|
const updated = [...current];
|
||||||
const removed = updated.splice(index, 1)[0];
|
const removed = updated.splice(index, 1)[0];
|
||||||
@@ -260,6 +262,7 @@ export class UploadFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
return updated;
|
return updated;
|
||||||
});
|
});
|
||||||
|
this.itemRemoved.emit({ index, id: itemToRemove.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
setFiles(files: File[], colors?: string[]) {
|
setFiles(files: File[], colors?: string[]) {
|
||||||
|
|||||||
@@ -139,6 +139,13 @@ export class QuoteEstimatorService {
|
|||||||
return this.http.patch(`${environment.apiUrl}/api/quote-sessions/line-items/${lineItemId}`, changes, { headers });
|
return this.http.patch(`${environment.apiUrl}/api/quote-sessions/line-items/${lineItemId}`, changes, { headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteLineItem(sessionId: string, lineItemId: string): Observable<any> {
|
||||||
|
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<any> {
|
createOrder(sessionId: string, orderDetails: any): Observable<any> {
|
||||||
const headers: any = {};
|
const headers: any = {};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user