Skip to content

Commit c2d84ae

Browse files
committed
allOrders URL implementation
1 parent 17a72d0 commit c2d84ae

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ public Order getOrderById(@PathVariable final String customerId, @PathVariable f
3434

3535
@RequestMapping(value = "/customer/{customerId}/orders", method = RequestMethod.GET)
3636
public List<Order> getOrdersForCustomer(@PathVariable final String customerId) {
37-
return orderService.getAllOrdersForCustomer(customerId);
37+
final List<Order> orders = orderService.getAllOrdersForCustomer(customerId);
38+
for (final Order order : orders) {
39+
final Link selfLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(CustomerController.class).getOrderById(customerId, order.getOrderId())).withSelfRel();
40+
order.add(selfLink);
41+
}
42+
return orders;
3843
}
3944

4045
@RequestMapping(value = "/customers", method = RequestMethod.GET)

0 commit comments

Comments
 (0)