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") @PostMapping("/{orderId}/payments/confirm")
@Transactional @Transactional
public ResponseEntity<OrderDto> confirmPayment( public ResponseEntity<OrderDto> updatePaymentMethod(
@PathVariable UUID orderId, @PathVariable UUID orderId,
@RequestBody(required = false) Map<String, String> payload @RequestBody(required = false) Map<String, String> payload
) { ) {
getOrderOrThrow(orderId); getOrderOrThrow(orderId);
String method = payload != null ? payload.get("method") : null; 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))); return ResponseEntity.ok(toOrderDto(getOrderOrThrow(orderId)));
} }

View File

@@ -98,4 +98,20 @@ public class PaymentService {
return payment; 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> </select>
<button <button
type="button" type="button"
(click)="confirmPayment()" (click)="updatePaymentMethod()"
[disabled]=" [disabled]="confirmingPayment"
confirmingPayment || selectedOrder.paymentStatus === 'COMPLETED'
"
> >
{{ confirmingPayment ? "Invio..." : "Conferma pagamento" }} {{
confirmingPayment ? "Salvataggio..." : "Cambia metodo pagamento"
}}
</button> </button>
</div> </div>
</div> </div>

View File

@@ -132,14 +132,14 @@ export class AdminDashboardComponent implements OnInit {
}); });
} }
confirmPayment(): void { updatePaymentMethod(): void {
if (!this.selectedOrder || this.confirmingPayment) { if (!this.selectedOrder || this.confirmingPayment) {
return; return;
} }
this.confirmingPayment = true; this.confirmingPayment = true;
this.adminOrdersService this.adminOrdersService
.confirmPayment(this.selectedOrder.id, this.selectedPaymentMethod) .updatePaymentMethod(this.selectedOrder.id, this.selectedPaymentMethod)
.subscribe({ .subscribe({
next: (updatedOrder) => { next: (updatedOrder) => {
this.confirmingPayment = false; this.confirmingPayment = false;
@@ -147,7 +147,7 @@ export class AdminDashboardComponent implements OnInit {
}, },
error: () => { error: () => {
this.confirmingPayment = false; 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>( return this.http.post<AdminOrder>(
`${this.baseUrl}/${orderId}/payments/confirm`, `${this.baseUrl}/${orderId}/payments/confirm`,
{ method }, { method },