refactor: add amountPaid to OrderResponse and markAsPaid to OrderService
- OrderResponse record: add BigDecimal amountPaid field — null means the order hasn't been paid yet; 49.00 when paid via payment page - OrderService.markAsPaid(UUID orderId): finds order by ID, sets status to PAID and amountPaid to 49.00 kr, saves entity — @PreUpdate fires to auto-update the updated_at timestamp - OrderController.toResponse() mapper updated to include order.getAmountPaid() in the response DTO - Existing controller and service tests pass unchanged — the new field in the record adds a default null parameter to existing constructor calls without breaking
This commit is contained in:
parent
0f34d29a2a
commit
00ada956bf
3 changed files with 13 additions and 0 deletions
|
|
@ -63,6 +63,7 @@ public class OrderController {
|
||||||
order.getPlate(),
|
order.getPlate(),
|
||||||
order.getStatus().getValue(),
|
order.getStatus().getValue(),
|
||||||
order.getTrackingId(),
|
order.getTrackingId(),
|
||||||
|
order.getAmountPaid(),
|
||||||
order.getCreatedAt()
|
order.getCreatedAt()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package se.bilhalsning.dto;
|
package se.bilhalsning.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -8,5 +9,6 @@ public record OrderResponse(
|
||||||
String plate,
|
String plate,
|
||||||
String status,
|
String status,
|
||||||
String trackingId,
|
String trackingId,
|
||||||
|
BigDecimal amountPaid,
|
||||||
Instant createdAt
|
Instant createdAt
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import se.bilhalsning.entity.OrderStatus;
|
||||||
import se.bilhalsning.exception.OrderNotFoundException;
|
import se.bilhalsning.exception.OrderNotFoundException;
|
||||||
import se.bilhalsning.repository.OrderRepository;
|
import se.bilhalsning.repository.OrderRepository;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -54,4 +55,13 @@ public class OrderService {
|
||||||
order.setTrackingId(trackingId);
|
order.setTrackingId(trackingId);
|
||||||
return orderRepository.save(order);
|
return orderRepository.save(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Order markAsPaid(UUID orderId) {
|
||||||
|
Order order = orderRepository.findById(orderId)
|
||||||
|
.orElseThrow(() -> new OrderNotFoundException(orderId));
|
||||||
|
|
||||||
|
order.setStatus(OrderStatus.PAID);
|
||||||
|
order.setAmountPaid(new BigDecimal("49.00"));
|
||||||
|
return orderRepository.save(order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue