AI Coding · Medium
The assistant wrote this endpoint to list orders with their customer names. What's wrong?
AI CodingCode ReviewSenior
Spring Boot 3 + JPA. Order has a @ManyToOne(fetch = LAZY) Customer customer. The page size is up to 500.
java
@GetMapping("/orders")
public List<OrderView> list(@RequestParam int page) {
List<Order> orders = orderRepository
.findAll(PageRequest.of(page, 500))
.getContent();
return orders.stream()
.map(o -> new OrderView(o.getId(),
o.getCustomer().getName(),
o.getTotal()))
.toList();
}