Merge pull request 'dev' (#20) from dev into main
All checks were successful
Build and Deploy / test-backend (push) Successful in 27s
Build and Deploy / test-frontend (push) Successful in 1m0s
Build and Deploy / build-and-push (push) Successful in 23s
Build and Deploy / deploy (push) Successful in 10s

Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
2026-03-04 15:33:02 +01:00
5 changed files with 30 additions and 11 deletions

View File

@@ -101,13 +101,16 @@ public class AdminOrderController {
@PostMapping("/{orderId}/payments/confirm")
@Transactional
public ResponseEntity<OrderDto> confirmPayment(
public ResponseEntity<OrderDto> updatePaymentMethod(
@PathVariable UUID orderId,
@RequestBody(required = false) Map<String, String> payload
) {
getOrderOrThrow(orderId);
String method = payload != null ? payload.get("method") : null;
paymentService.confirmPayment(orderId, method);
if (method == null || method.isBlank()) {
throw new ResponseStatusException(BAD_REQUEST, "Payment method is required");
}
paymentService.updatePaymentMethod(orderId, method);
return ResponseEntity.ok(toOrderDto(getOrderOrThrow(orderId)));
}

View File

@@ -98,4 +98,20 @@ public class PaymentService {
return payment;
}
@Transactional
public Payment updatePaymentMethod(UUID orderId, String method) {
if (method == null || method.isBlank()) {
throw new IllegalArgumentException("Payment method is required");
}
Order order = orderRepo.findById(orderId)
.orElseThrow(() -> new RuntimeException("Order not found with id " + orderId));
Payment payment = paymentRepo.findByOrder_Id(orderId)
.orElseGet(() -> getOrCreatePaymentForOrder(order, "OTHER"));
payment.setMethod(method.trim().toUpperCase());
return paymentRepo.save(payment);
}
}

View File

@@ -163,12 +163,12 @@
</select>
<button
type="button"
(click)="confirmPayment()"
[disabled]="
confirmingPayment || selectedOrder.paymentStatus === 'COMPLETED'
"
(click)="updatePaymentMethod()"
[disabled]="confirmingPayment"
>
{{ confirmingPayment ? "Invio..." : "Conferma pagamento" }}
{{
confirmingPayment ? "Salvataggio..." : "Cambia metodo pagamento"
}}
</button>
</div>
</div>

View File

@@ -132,14 +132,14 @@ export class AdminDashboardComponent implements OnInit {
});
}
confirmPayment(): void {
updatePaymentMethod(): void {
if (!this.selectedOrder || this.confirmingPayment) {
return;
}
this.confirmingPayment = true;
this.adminOrdersService
.confirmPayment(this.selectedOrder.id, this.selectedPaymentMethod)
.updatePaymentMethod(this.selectedOrder.id, this.selectedPaymentMethod)
.subscribe({
next: (updatedOrder) => {
this.confirmingPayment = false;
@@ -147,7 +147,7 @@ export class AdminDashboardComponent implements OnInit {
},
error: () => {
this.confirmingPayment = false;
this.errorMessage = 'Conferma pagamento non riuscita.';
this.errorMessage = 'Aggiornamento metodo pagamento non riuscito.';
},
});
}

View File

@@ -59,7 +59,7 @@ export class AdminOrdersService {
});
}
confirmPayment(orderId: string, method: string): Observable<AdminOrder> {
updatePaymentMethod(orderId: string, method: string): Observable<AdminOrder> {
return this.http.post<AdminOrder>(
`${this.baseUrl}/${orderId}/payments/confirm`,
{ method },